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

What is the difference between text and binary i/o?

592


how is the examination pattern?

1597


in iso what are the common technological language?

1637


How do you define a string?

656


Which programming language is best for getting job 2020?

607






What is a c token and types of c tokens?

591


What the different types of arrays in c?

614


How can this be legal c?

652


What is difference between structure and union?

601


What is the difference between malloc() and calloc()?

617


Is c weakly typed?

579


Create a structure to specify data on students as given below: Roll number, Name, Department, Course, and Year of joining. Assume that there are not more than 450 students in the collage. (a) Write a function to print the names of all students who joined in the last 3 years. (b) Write a function to print the data of a student whose roll numbers are divisible by 4.

604


How do I use void main?

634


How can I access an I o board directly?

624


What is the difference between union and structure in c?

577