write a program to find the largest and second largest
integer from an array
Answer Posted / 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 |
Post New Answer View All Answers
What are valid operations on pointers?
What is volatile keyword in c?
Why do some versions of toupper act strangely if given an upper-case letter?
What is the meaning of c in c language?
Which header file is essential for using strcmp function?
Create a simple code fragment that will swap the values of two variables num1 and num2.
Explain what is #line used for?
How many types of sorting are there in c?
what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above
Which driver is a pure java driver
Explain what is the benefit of using #define to declare a constant?
Explain what is the difference between far and near ?
Why can arithmetic operations not be performed on void pointers?
Explain what is operator promotion?
What is static function in c?