write a program to fined second smallest and largest element
in a given series of elements (without sorting)

Answer Posted / nikhil kumar saraf

void main()
{
int a[12],max,min,min2,i;
printf("enter values");
for(i=0;i<10;i++)
scanf(%d,&a[i]);
max=a[0];
min=a[0];
for(i=0;i<10;i++)
{
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
}
min2=a[0];
for(i=0;i<10;i++)
{
if(min2>a[i] && a[i]!=min)
{
min2=a[i];
}
printf("The second smallest element is:-%d",min2);
printf("The largest element is:-%d",max);
getch();
}

Is This Answer Correct ?    2 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

If errno contains a nonzero number, is there an error?

911


how to find binary of number?

3657


What is #include cctype?

667


What is the code for 3 questions and answer check in VisualBasic.Net?

1782


Is c object oriented?

630






What does return 1 means in c?

666


Explain what is the difference between null and nul?

768


What is %g in c?

737


What is putchar() function?

733


write a programming in c to find the sum of all elements in an array through function.

1807


Why is python slower than c?

705


How can you invoke another program from within a C program?

705


Is using exit() the same as using return?

778


What is the difference between mpi and openmp?

837


a c code by using memory allocation for add ,multiply of sprase matrixes

2407