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
How do I get a null pointer in my programs?
What is pointer to pointer in c language?
What does node * mean?
Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?
What is a structure in c language. how to initialise a structure in c?
What is a structure and why it is used?
What does %c mean in c?
What is c system32 taskhostw exe?
Why we write conio h in c?
What is the general form of #line preprocessor?
When should a far pointer be used?
What is structure in c definition?
A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.
What are the advantages of the functions?
Why isnt any of this standardized in c?