C++ Program to find out the largest number in the given array




An array is a collection of identical objects which are stored in consecutive memory locations under a common heading or a variable name. In other words, an array is a group or a table of values referred to by the same variable name.

Program Description: Here is a c++ program to read a set of numbers from the keyboard and to find out the largest number in the given array (the numbers are stored in a random order).

Program Code:
#include
void main (void)
{
int a[100];
int i,n,larg;
cout << "How many numbers are in the array?" << endl;
cinn >> n;
cout << "Enter the elements" << endl;
for (i=0;i<=n-1;++i)
{
cin >> a[i];
}
cout << "Contents of the array" << endl;
for (i=0; i<=n-1;++i)
{
cout << a[i] << '\t';
}
cout << endl;
larg = a[0];
for (i=0;i<=n-1;++i)
{
if (larg < a[i])
larg = a[i];
}
cout << "Largest value in the array =" << larg;
}

Output of the above program:
How many numbers are in the array?
5
Enter the elements
11 23 45 67 3
Contents of the array
11 23 45 67 3
Largest value in the array = 67


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: