google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a c++ program to find second largest of n numbers in the array - 2nd puc computer science

Write a c++ program to find second largest of n numbers in the array

// Write a c++ program to find second largest of n numbers in the array

#include<iostream.h> 

#include<conio.h> 

void main( )

{

int a[50], i, n, largest, secondlar; 

clrscr( );

cout<<"How many elements?"; 

cin>>n;

cout<<"Enter the elements:\n"; 

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

cin>>a[i]; 

if(a[0] > a[1])

{

largest = a[0]; 

secondlar = a[1];

}

else

{

largest=a[1];

secondlar=a[0];

}

for(i=2;i<n;i++)

if(a[i]>largest)

{

secondlar=largest;

largest=a[i]; 

else if(a[i]>secondlar)

secondlar=a[i];

cout<<"Largest = "<<largest<<endl;

cout<<"Second Largest = "<<secondlar<<endl; 

getch( );

}

Write a c++ program to find second largest of n numbers in the array Write a c++ program to find second largest of n numbers in the array Reviewed by Vision Academy on February 27, 2022 Rating: 5

No comments:

CheckOut

Powered by Blogger.