Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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 the given no is odd or even without checking of any condition and loops. (Hint: Using array)

4 Answers  


What is a keyword?

0 Answers  


write a C program to print the program itself ?!

16 Answers   TCS,


What are disadvantages of C language.

0 Answers   iNautix,


program to find which character is occured more times in a string and how many times it has occured? for example in the sentence "i love india" the output should be i & 3.

3 Answers  


What is the method to save data in stack data structure type?

0 Answers  


Is c is a high level language?

0 Answers  


what will be the output of this program? void main() { int a[]={5,10,15}; int i=0,num; num=a[++i] + ++i +(++i); printf("%d",num); }

6 Answers   Microsoft,


Multiply an Integer Number by 2 Without Using Multiplication Operator

0 Answers  


Program will then find the largest of three numbers using nested if-else statements. User is prompted to enter three numbers. Program will find the largest number and display it on the screen. All three numbers entered by the user are also displayed. If user enters 21, 33, and 5, the output should be as follows: You entered: 21, 33 and 5. The largest number is 33.

0 Answers  


What is 'bus error'?

0 Answers  


DIFFERNCE BETWEEN THE C++ AND C LANGUAGE?

2 Answers   Wipro,


Categories