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
Write a program that accept anumber in words
What is difference between static and global variable in c?
The process of repeatedly running a set of computer instructions until some condition is specifed a) condition b) sequential condition c) global d) iteration
Suggesting that there can be 62 seconds in a minute?
Is the exit() function same as the return statement? Explain.
What are the complete rules for header file searching?
Where is volatile variable stored?
Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......
c program for searching a student details among 10 student details
What is unsigned int in c?
What is NULL pointer?
how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?
Write a program to print factorial of given number without using recursion?
On most computers additional memory that is accessed through an adapter of feature card along with a device driver program. a) user memory b) conventional memory c) expandedmemory d) area
what type of questions arrive in interview over c programming?