write a program to fined second smallest and largest element
in a given series of elements (without sorting)

Answer Posted / vadivel t

#include<stdio.h>

void main()
{
int a[10] = {5,4,1,7,3,0,8,23,12,24};
int Lcount = 0, Gcount = 0, i, j;

for(i = 0; i<10; i++)
{
Gcount = 0;
Lcount = 0;
for(j = 0; j<10; j++)
{
if(a[i] > a[j])
{
Gcount++;
Lcount++;
}
}
if(Gcount == 8)
{
printf("The second largest no is: %
d \n", a[i]);
}
if(Lcount == 1)
{
printf("The second smallest no is: %
d \n", a[i]);
}
}
_getch();
}

Is This Answer Correct ?    2 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

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

780


design and implement a data structure and performs the following operation with the help of file (included 1000 student marks in 5 sub. and %also) 1.how many students are fail in all 5 subjects (if >35) 2. delete all student data those are fail in all 5 subjects. 3. update the grace marks (5 no. if exam paper is 100 marks) 4. arrange the student data in ascending order basis of marks. 5.insert double of deleted students with marks in the list.

1599


What is c language and why we use it?

703


write a progrmm in c language take user interface generate table using for loop?

1665


What is the size of a union variable?

685






What are 'near' and 'far' pointers?

716


What is the purpose of void pointer?

686


why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???

1609


What is const volatile variable in c?

672


Tell me can the size of an array be declared at runtime?

680


write a c program to do the following: a) To find the area of a triangle. b) To convert the temperature from Fahrenheit to Celsius. c) To convert the time in hours : minutes : seconds to seconds.

1624


What does int main () mean?

631


Differentiate between declaring a variable and defining a variable?

707


How to set file pointer to beginning c?

771


What is c programing language?

701