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 is difference between stdio h and conio h?

997


write a programe to accept any two number and check the following condition using goto state ment.if a>b,print a & find whether it is even or odd and then print.and a

1541


What is indirection in c?

707


a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above

819


What is %d used for?

676






What is the use of getch ()?

726


What is a function in c?

676


What is structure in c language?

717


What is bubble sort in c?

729


Describe the steps to insert data into a singly linked list.

721


A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none

830


What is the Purpose of 'extern' keyword in a function declaration?

739


If I have a char * variable pointing to the name of a function ..

758


What is a program?

776


What is the default value of local and global variables in c?

651