write a program to find the largest and second largest
integer from an array

Answers were Sorted based on User's Feedback



write a program to find the largest and second largest integer from an array..

Answer / manish gupta

#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],x,y,c;
for (x=0;x<5;x++)
{
printf("enter any number");
scanf("%d",&a[x]);
}
for (x=0;x<5;x++)
{
for (y=0;y<4;y++)
{
if (a[y]>a[y+1])
{
c=a[y];
a[y]=a[y+1];
a[y+1]=c;
}
}
}
printf("\nlargest no:-%d",a[y]);
printf("\nsecond largest no:-%d",a[y-1]);
getch();
}

Is This Answer Correct ?    17 Yes 8 No

write a program to find the largest and second largest integer from an array..

Answer / mahesh

use bubble sort next to this, print last n second from last..

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C Interview Questions

How can I remove the trailing spaces from a string?

0 Answers   Aspire,


how to find the size of the data type like int,float without using the sizeof operator?

13 Answers  


What is difference between structure and union in c?

0 Answers  


main() { int x, arr[8]={11,22,33,44,55,66,77,88}; x=(arr+2)[3]; printf(“%d”,x); }

8 Answers   Vector,


Explain pointers in c programming?

0 Answers  


what is the difference between embedded c and turbo c ?

1 Answers  


hi... can anyone help me to make a two-dimensinal arrays in finding the sum of two elements plzzz. thnx a lot...

0 Answers  


what is the role you expect in software industry?

2 Answers   HCL, Wipro,


What is the purpose of realloc()?

0 Answers  


Where define directive used?

0 Answers  


Is null always defined as 0(zero)?

0 Answers  


Average of a couple 10 years ago was 25. The average remains same after having a child and twins after 3 years. What is the present age of the first child

10 Answers   IBM, Infosys,


Categories