October 7, 2024
c-program c ++

Program to Calculate 2nd Highest Number Form N Number

Program to Calculate 2nd Highest Number Form N Number

#include
#include
int main(){
clrscr();
int n,i,tem,j,k,l;
float x[20];

cout<<”      ” This program will show second highest number form some number.””<<endl<<endl;
xx:
cout<<“How many numbers ? Give a integer number”<<endl;
cin>>n;

if(n>20) {
cout<<“More then 20 is not allow. Please give less then 20″<<endl;
goto xx;
}

if(n<0){
cout<<“Negative number not allow, Please give a positive integer number.”<<endl;
goto xx;
}

if(n==0){
cout<<“0 is not valid,Please give a large number.”<<endl;
goto xx;
}

cout<<“What are the elements ?. Give “<<n<<” numbers”<<endl;
for(i=1;i<=n;i++)
cin>>x[i];

cout<<endl<<endl;
cout<<“You have given the following numbers:”<<endl;
for(i=1;i<=n;i++)
cout<<x[i]<<” “;

for(i=1;i<=n;i++)
for(j=1;j<=n;j++) {
if(x[i] > x[j]) {
tem=x[i];
x[i]=x[j];
x[j]=tem;
}
}

cout<<endl;

k=1;
cout<<“Second highest number is: “<<endl;
for(i=k;i<=n;i++){
if((x[k]) == (x[k+1]))
k++;
}

if (k==n) cout<<0;
else  cout<<x[k+1];

getch();
}

Rashedul Alam

I am a software engineer/architect, technology enthusiast, technology coach, blogger, travel photographer. I like to share my knowledge and technical stuff with others.

View all posts by Rashedul Alam →

Leave a Reply

Your email address will not be published. Required fields are marked *