OOPC Practical 4


Practical : 4
Subject : Object Oriented Programming with C++

Aim : C++ Program to find second largest element


Source Code :
#include<iostream.h>
#include<conio.h>
void asc(int a[5] )
{
int i,j,temp;
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
   if(a[i] > a[j])
   {
     temp = a[i];
     a[i] = a[j];
     a[j] = temp;
     }
   }
 }
}
 void main()
{
 clrscr();
 int i , a[5] , j, temp;
 for(i=0;i<5;i++)
{
 cout << "enter numbers: ";
 cin >> a[i];
 }
 asc(a);
 cout << "sorted array :";
 for(i=0;i<5;i++)
{
cout<<"\n"<< a[i] ;
}
cout << "\n second largest element:  " << a[i-2];
getch();
}

Output :


Pratik Boghani

Author & Editor

Life is all about the next step.

0 comments:

Post a Comment