In this program we are going to find the largest number in the array. All we are doing in this program is that we are taking one array element as check and we are comparing it with other elements of array and storing the result in that check element of array. In my program we are taking a[0] as a check element and we are storing the result in it.
Program:
// Program By http://solutionscpp.blogspot.com// Author Mansoor Ahmed
// GMail ID: secguy000@gmail.com
#include<iostream>
using namespace std;
int main()
{
int a[10];
for(int i=0; i<10; i++)
{
cout<<"Enter " <<i <<" Element of array: ";
cin>>a[i];
}
for(int j=0; j<10; j++)
{
if(a[0]<a[j]) /* Change sign '<' to sign '>' if you want to find smallest element of array*/
a[0]=a[j];
}
cout<<"The Largest Elemet of Array is: " <<a[0];
}
Output:
Note:
By Changing sign '<' to sign '>' you can find the smallest element of array.
0 comments: