C++ PRACTICAL PROGRAMS

Class 12 Computer Science | ASSEB

Program to find the largest (maximum) element of an array

#include<iostream>

using namespace std;

int main( )

{

int a[50], n, max;

cout<<”Enter number of elements”;

cin>>n;

cout<<”Enter array elements”;

for( int i=0; i<n; i++)

{

cin>>a[i];

}

max=a[0];

for( int i=1; i<n; i++)

{

if (a[i] > max) {

max=a[i];  }

}

cout<<”\n Maximum number in the array is ”<<max;

return 0;

}

Output

Enter number of elements 5

Enter array elements 6

9

2

4

5

Maximum number in the array is 9

QUICK LINKS

Class 11

Class 12

Previous Year Paper

Practical Programs

Scroll to Top