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
a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion
Write a program to check palindrome number in c programming?
Explain the use of function toupper() with and example code?
Should I learn c before c++?
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?
Define Spanning-Tree Protocol (STP)
Difference between Shallow copy and Deep copy?
A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference
What is the code in while loop that returns the output of given code?
What are the types of i/o functions?
Explain goto?
What is restrict keyword in c?
What are local variables c?
what is the difference between class and unio?
What is difference between structure and union in c?