Saturday, August 27, 2011

How to find the Largest element in array using C++.


//Program to find the Largest element in array using C++.
#include<iostream.h>
#include<conio.h>
void main()
{
 int i, k, loc, max, data[50], n;
 clrscr();
 cout<<endl<<"Enter the number of elements in the array:";
 cin>>n;
 cout<<endl<<"Enter the value of "<<n<<" elements:";
 for(i=0; i<n; i++)
 {
  cin>>data[i];
 }
 loc=0;
 max=data[0];
 for(k=0; k<n; k++)
 {
  if(max<data[k])
  {
   loc=k;
   max=data[k];
  }
 }
 cout<<endl<<"Largest element is "<<max<<" and its location is "<<loc;
 getch();
}

Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More