Welcome..!!

Please visit http://csprograms.in/ for more Computer Science programs.

Wednesday 14 March 2012

12. C++ program to find largest among 'n' numbers.



#include <iostream>
int main()
{
int i,n,m; 
cout <<"Enter the total number \n";
cin >>n;
cout <<"The total number of array is \n"<<n;
for(i=1;i<=n;i++)
cin >>a[i];
cout <<"The entered array is \n";
for(i=1;i<=n;i++)
cout <<"\n"<<a[i];
m = a[1];
for(i=2;i<=n;i++)
{
if(m<a[i])
m = a[i];
}
cout <<"The largest number is \n"<< m;
return 0;
}

6 comments:

  1. Gives an error when you compile saying that "unidentified symbol a" on the line
    cin>>a[i];

    ReplyDelete
  2. we must declare size of array
    int i,n,m,a[20];
    where a[20] is the size of a.It may depend on your required memory allocation.

    ReplyDelete
  3. Thanks it's very simple and clearable code

    ReplyDelete