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

Answer Posted / srijit

#include<stdio.h>
#include<conio.h>


int main()
{
int size,a[100],i,j=0,k=0,min1,min2;
printf("Input size of an array\n");
scanf("%d",&size);
printf("Input the %d elements of the array\n",size);
for(i=0;i<size;i++)
scanf("%d",&a[i]);

min1=a[0];
for(i=0;i<size;i++)
{
if(a[i]<min1)
{
min1=a[i];
j=i;
}

}
for(i=0;i<size;i++)
{
if(i!=j)
{
min2=a[i];
break;
}
}

for(i=0;i<size;i++)
{
if((i!=j)&&a[i]<min2)
{
min2=a[i];
}

}
printf("Second minimam element of the array is %d\n",min2);


getch();


}

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion

2308


Write a program to check palindrome number in c programming?

572


Explain the use of function toupper() with and example code?

620


Should I learn c before c++?

559


Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?

550






Define Spanning-Tree Protocol (STP)

616


Difference between Shallow copy and Deep copy?

1548


A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference

602


What is the code in while loop that returns the output of given code?

1243


What are the types of i/o functions?

651


Explain goto?

687


What is restrict keyword in c?

619


What are local variables c?

523


what is the difference between class and unio?

1837


What is difference between structure and union in c?

520