Write a Program to Find a Largest Number in a Array.

Working

  • Make an Array.
  • Set First Element as Max Number.
  • Compare Each Element with Max Number
  • If New Number is Greater Then Max Number Then New Number Assign as Max Number.
  • In End Max Number.
  • Max Number is Maximum Number in a Array.

Program

//Find a Largest Number in a Array
#include<iostream.h>
#include<conio.h>
int max_number(int arry[],int len){
int max_num = 0;
for(int i=0;i<len;i++){
if(arry[i]>max_num){
max_num=arry[i];
}
}
return max_num;
}
void main(){
clrscr();
int max,len=0;
int array[50];
cout<<"\n Find a Largest Number in a Array ";
cout<<"\n -------------------------------- ";
cout<<"\n Enter a Length of Array ";
cin>>len;
cout<<" Enter the "<<len<<" Numbers \n";
for(int i=0;i<len;i++){
cout<<" Value "<<i+1<<" : ";
cin>>array[i];
}
max = max_number(array,len);
cout<<"\n The largest Number in Array is "<<max;
getch();
}

 

Output 

 

(Visited 52 times, 1 visits today)
Share with Friends :