Write a program that read 2o numbers in and array and
output the second largest number. Can anybody help??

Answer Posted / ajit

#include<stdio.h>
void main()
{
int a[20],i,j,temp;
printf("enter the 20 values\n");
for(i=0;i<20;i++)
scanf("%d",&a[i]);
for(i=0;i<20;i++)
{
for(j=i+1;j<20;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("the second largest number is %d\n",a[18]);
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a pdb file?

544


What is pointer in c++ with example?

522


What is the error in the code below and how should it be corrected?

313


What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator?

642


What's the most powerful programming language?

601






What is c++ similar to?

603


If you hear the cpu fan is running and the monitor power is still on, but you did not see anything show up in the monitor screen. What would you do to find out what is going wrong?

554


How to tokenize a string in c++?

607


Difference between inline functions and macros?

600


Why c++ is better than c language?

567


Perform addition, multiplication, subtraction of 2-D array using Operator Overloading.

3375


How do you print a string on the printer?

583


Define anonymous class.

627


Why iomanip is used in c++?

643


What is the difference between structures and unions?

585