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 static and auto variables in c?
how to capitalise first letter of each word in a given string?
Subtract Two Number Without Using Subtraction Operator
Explain how can I read and write comma-delimited text?
Explain 'far' and 'near' pointers in c.
how to find anagram without using string functions using only loops in c programming
the factorial of non-negative integer n is written n! and is defined as follows: n!=n*(n-1)*(n-2)........1(for values of n greater than or equal to 1 and n!=1(for n=0) Perform the following 1.write a c program that reads a non-negative integer and computes and prints its factorial. 2. write a C program that estimates the value of the mathematical constant e by using the formula: e=1+1/!+1/2!+1/3!+.... 3. write a c program the computes the value ex by using the formula ex=1+x/1!+xsquare/2!+xcube/3!+....
Is calloc better than malloc?
Can a pointer be null?
What does typeof return in c?
Explain what is the difference between far and near ?
Explain why c is faster than c++?
What are header files and what are its uses in C programming?
what is the different bitween abap and abap-hr?
Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?