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 Help Members By Posting Answers For Below Questions

What is static and auto variables in c?

567


how to capitalise first letter of each word in a given string?

1434


Subtract Two Number Without Using Subtraction Operator

357


Explain how can I read and write comma-delimited text?

656


Explain 'far' and 'near' pointers in c.

706






how to find anagram without using string functions using only loops in c programming

2718


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!+....

22230


Is calloc better than malloc?

578


Can a pointer be null?

565


What does typeof return in c?

639


Explain what is the difference between far and near ?

651


Explain why c is faster than c++?

575


What are header files and what are its uses in C programming?

637


what is the different bitween abap and abap-hr?

1743


Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?

597