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 give me a VIRTUSA sample palcement papers.... you will only send TECHNICAL SECTION..... that is help for me Advance Thanks........................
What is a pointer value and address in c?
Why should I prototype a function?
How to get string length of given string in c?
Is null valid for pointers to functions?
write a program that reads lines(using getline), converts each line to an integer using atoi, and computes the average of all the numbers read. also compute the standard deviation.
a program that can input number of records and can view it again the record
PLS U SENS ME INTERVIEW O. MY EMAIL ADD, SOFIYA.SINGH@GMAIL.COM
Why do we use header files in c?
What does int main () mean?
Write a progarm to find the length of string using switch case?
What are header files why are they important?
What is scope of variable in c?
What does void main return?
Explain how can you restore a redirected standard stream?