find second largest element in array w/o using sorting
techniques? use onle one for loop.

Answers were Sorted based on User's Feedback



find second largest element in array w/o using sorting techniques? use onle one for loop...

Answer / sazzadcsedu

int max,secMax;
int A[100];
if(A[0]>A[1])
{
max=A[0];
secMax=A[1];
}
else
{
max=A[1];
secMax=A[0];

}


for(i=2;i<=length of Array;i++)
{
if (A[i]>max )
{
secMax=max;
max=A[i];
}
else if(array[i]>secMax)
{
secMax = A[i];
}

}

Is This Answer Correct ?    7 Yes 7 No

find second largest element in array w/o using sorting techniques? use onle one for loop...

Answer / ramesh

this is to largest element in an array using one loop concept:

for(int i=0;i<=arr.length;i++)
{
if(a[i]>a[i+1])//if first position element is large we want swap that element
{
t =a[i];
a[i] =a[i+1];
a[i+1]=t;
}
printf("%d",a[i+1]);

by
97894 33227

Is This Answer Correct ?    1 Yes 3 No

find second largest element in array w/o using sorting techniques? use onle one for loop...

Answer / k.shravan

main()
{

int a[10],min,max,temp,i;
clrscr();
printf("\n\n Enter the array=>");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
min=max=a[0];

for(i=1;i<5;i++)
{
if(a[i]>max)
{
min=max;
max=a[i];
}

if(a[i]<max && a[i]>min)
{
min=a[i];
}

}
printf("%d---%d",max,min);

getch();
}

Is This Answer Correct ?    7 Yes 11 No

find second largest element in array w/o using sorting techniques? use onle one for loop...

Answer / anamika datta

#include<stdio.h>
#include<conio.h>
void main()
{
int n[]={5,3,4};
int i,large,sec_large;
clrscr();

large=sec_large=n[0];
for(i=0;i<3;i++)
{
if(n[i]>large)
{
sec_large=large;
large=n[i];
}

}
printf("%d",sec_large);
}
getch();

Is This Answer Correct ?    10 Yes 19 No

find second largest element in array w/o using sorting techniques? use onle one for loop...

Answer / guest


max = 2ndmax= array[0];
for (i=0;i,length;i++)
{
if (array[i]>max)
{
2ndmax=max;
max=array[i];
}
}
return 2nd max

Is This Answer Correct ?    40 Yes 74 No

Post New Answer

More C Interview Questions

how to find that no is int or float?

5 Answers  


How can you be sure that a program follows the ANSI C standard?

0 Answers   Aspire, Infogain,


What is wrong in this statement? scanf(“%d”,whatnumber);

0 Answers  


What is a program flowchart and explain how does it help in writing a program?

0 Answers  


how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software

0 Answers  






what is the output of the following program and explain the answer #include<stdio.h> exp() { main(5) } main(int a) { printf("%d",a); return; }

3 Answers   Satyam,


What's the best way of making my program efficient?

0 Answers   Celstream,


Write a program that takes a 5 digit number and calculates 2 power that number and prints it

7 Answers  


why we wont use '&' sing in aceesing the string using scanf

0 Answers   HCL,


24.what is a void pointer? 25.why arithmetic operation can’t be performed on a void pointer? 26.differentiate between const char *a; char *const a; and char const *a; 27.compare array with pointer? 28.what is a NULL pointer? 29.what does ‘segmentation violation’ mean? 30.what does ‘Bus Error’ mean? 31.Define function pointers? 32.How do you initialize function pointers? Give an example? 33.where can function pointers be used?

0 Answers  


c program to add and delete an element from circular queue using array

3 Answers  


What is New modifiers?

0 Answers   NA,


Categories