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

Write a program that accept anumber in words

1484


What is difference between static and global variable in c?

771


The process of repeatedly running a set of computer instructions until some condition is specifed a) condition b) sequential condition c) global d) iteration

851


Suggesting that there can be 62 seconds in a minute?

806


Is the exit() function same as the return statement? Explain.

860


What are the complete rules for header file searching?

865


Where is volatile variable stored?

844


Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......

1972


c program for searching a student details among 10 student details

1880


What is unsigned int in c?

754


What is NULL pointer?

863


how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?

1741


Write a program to print factorial of given number without using recursion?

783


On most computers additional memory that is accessed through an adapter of feature card along with a device driver program. a) user memory b) conventional memory c) expandedmemory d) area

923


what type of questions arrive in interview over c programming?

1776