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


Please Help Members By Posting Answers For Below Questions

What are the advantages of using macro in c language?

596


What does s c mean on snapchat?

590


Why do we use null pointer?

609


What is the value of a[3] if integer a[] = {5,4,3,2,1}?

677


What are the types of unary operators?

667






What is the size of a union variable?

604


If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?

782


What is typedf?

674


What do you understand by friend-functions? How are they used?

653


Why pointers are used?

634


Do pointers take up memory?

666


Can we declare variables anywhere in c?

583


writ a program to compare using strcmp VIVA and viva with its output.

1530


Explain how can I pad a string to a known length?

661


What is the acronym for ansi?

636