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

What are the properties of union in c?

835


For what purpose null pointer used?

839


What is string function in c?

776


What is return type in c?

908


hi folks i m approching for h1 b interview on monday 8th of august at montreal and i m having little problem in my approval notice abt my bithdate my employer has made a mistake while applying it is 12th january and istead of that he had done 18 the of january do any body have any solution for that if yes how can i prove my visa officer abt my real birthdate it urgent please let me know guys thaks dipesh patel

1660


Explain how to reverse singly link list.

866


what will be maximum number of comparisons when number of elements are given?

1686


How do you list files in a directory?

839


Explain Function Pointer?

932


Describe dynamic data structure in c programming language?

850


When should a type cast be used?

787


What is the need of structure in c?

817


How does pointer work in c?

865


What is variables in c?

835


Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)

2110