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
Explain how does free() know explain how much memory to release?
What are the different types of constants?
What does %c do in c?
Explain what is gets() function?
What are runtime error?
What is the main difference between calloc () and malloc ()?
Can we assign string to char pointer?
How can I change their mode to binary?
Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.
Why cant I open a file by its explicit path?
Is int a keyword in c?
Write a program which returns the first non repetitive character in the string?
What is c language and why we use it?
What is difference between far and near pointers?
What is your stream meaning?