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 output redirection?
How can I automatically locate a programs configuration files in the same directory as the executable?
Does c have class?
difference between native and cross compilers
What is bss in c?
What are the key features in c programming language?
Why doesnt that code work?
Explain how do you list a file’s date and time?
What are the different types of control structures in programming?
Can a variable be both const and volatile?
What is quick sort in c?
How can I swap two values without using a temporary?
Explain what is the stack?
Write a C program to count the number of email on text
How can I write functions that take a variable number of arguments?