C / C++ Program to find the Largest number from the array of integers

Leave a Comment
/* The following C / C++ Program will find the largest number among numbers in the integer array thus entered by the user. We have used while loop to read & write the array*/

Code:-
#include<iostream>
#include<conio.h>
using namespace std;
void main ()
{
int a[100];
int max,b=0,c,n;
cout<<"\nEnter the total number of elements in array(<100):";
cin>>n;
while (b<n)
{
cout<<"Enter the element number "<<b<<" : ";
cin>>c;
a[b]=c;
b=b+1;
}
b=0;
max=a[b];
//assuming that the 1st element is the maximum
while (b<n)
{
if (a[b]>=max)
//if anything else is found to be more larger than the current maximum
{
max=a[b];
}
b=b+1;
}
cout<<"\nLargest number is : "<<max;
getche();
}



Output:
C / C++ Program to find the Largest number from the array of integers
C / C++ Program to find the Largest number from the array of integers

0 comments: