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
in linking some of os executables are linking name some of them
How is = symbol different from == symbol in c programming?
What is data type long in c?
What are lookup tables in c?
What is the use of getchar() function?
In which header file is the null macro defined?
What are the three constants used in c?
How do I determine whether a character is numeric, alphabetic, and so on?
What are shell structures used for?
we called a function and passed something do it we have always passed the "values" of variables to the called function. such functions calles are called a) calls by reference b) calls by value c) calls by zero d) none of the above
Write a program of advanced Fibonacci series.
Why main function is special give two reasons?
Explain the Difference between the New and Malloc keyword.
How many types of sorting are there in c?
How can you be sure that a program follows the ANSI C standard?