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 else syntax in c++?

738


What is an overflow error?

717


What are the benefits of c++?

674


What are the rules about using an underscore in a c++ identifier?

720


What is the full form of c++?

717






how can i access a direct (absolute, not the offset) memory address? here is what i tried: wrote a program that ask's for an address from the user, creates a FAR pointer to that adress and shows it. then the user can increment/decrement the value in that address by pressing p(inc+) and m(dec-). NOW, i compiled that program and opened it twice (in 2 different windows) and gave twice the same address to it. now look what happen - if i change the value in one "window" of the program, it DOES NOT change in the other! even if they point to the same address in the memory! here is the code snippet: //------------------------------------------------------ #include //INCLUDE EVERY KNOWN HEADER FILE #include //FOR ANY CASE... #include #include #include main() { int far *ptr; //FAR POINTER!!! long address; char key=0; //A KEY FROM THE KEYBOARD int temp=0; clrscr(); cout<<"Enter Address:"; cin>>hex>>address; //GETS THE ADDRESS clrscr(); (long)ptr=address; temp=*ptr; //PUTS THE ADDRESS IN THE PTR cout<<"["<

1906


What are the advantages of c++? Explain

682


How do I run c++?

673


Draw a flow chart and write a program for the difference between the sum of elements with odd and even numbers. Two dimensional array.

6007


What kind of problems can be solved by a namespace?

694


What is static class data?

658


What is an html tag?

720


How can you prevent accessing of the private parts of my class by other programmers (violating encapsulation)?

738


declare an array of structure where the members of the structure are integer variable float variable integer array char variable access all elements of the structure using dot operator and this pointer operator

1840


Define pre-condition and post-condition to a member function in c++?

761