Searching...
Wednesday, 4 January 2017

Maximum or largest number in array c++ code

Maximum or largest number in array c++ code

Write a C++ Program    which find largest or maximum number in array using for loop and if statement Concept used
  • Array in c++
  • for loop
  • if statement



Post contains c++ code and Dry run of code
How program works
  • Program  first take  size of array from user
  • Then input element or array one by one
  • then show the maximum number in array

Program:

#include<iostream>
using namespace std;
int main()
{

int size;
 cout<"Enter The Size Of Array:   ";
cin>>size;
int array[size], key,i;

// Taking Input In Array
for(int j=0;j<size;j++){
cout<<"Enter "<<j<<" Element : ";
cin>>array[j];
}
//Your Entered Array Is
for(int a=0;a<size;a++){
cout<<"array[ "<<a<<" ]  =  ";
cout<<array[a]<<endl;
}

int  maximum=array[0];
for(int i=0;i<size;i++){

if(array[i]>maximum){
maximum=array[i];
}
}

cout<<"nnMaximum Number is in array is :"<<maximum;
return 0;

}

0 comments:

Post a Comment