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
What is difference between stdio h and conio h?
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
What is indirection in c?
a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above
What is %d used for?
What is the use of getch ()?
What is a function in c?
What is structure in c language?
What is bubble sort in c?
Describe the steps to insert data into a singly linked list.
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
What is the Purpose of 'extern' keyword in a function declaration?
If I have a char * variable pointing to the name of a function ..
What is a program?
What is the default value of local and global variables in c?