Resources » Articles/Knowledge Sharing » Computer & Technology

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

Updated: Category: Computer & Technology
Author: Member Level: DiamondPoints: 2

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:
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?
Enter the elements
11 23 45 67 3
Contents of the array
11 23 45 67 3
Largest value in the array = 67

Did you like this resource? Share it with your friends and show your love!

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

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


Post 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)

    Type the numbers and letters shown on the left.

    Submit Article     Return to Article Index
    Complete the action items below to enter to win an iPad Mini from India Study Channel! in India Study Channel - Locker on LockerDome
    Awards & Gifts
    Active Members
    TodayLast 7 Daysmore...

    ISC Technologies, Kochi - India. © All Rights Reserved.