find second largest element in array w/o using sorting
techniques? use onle one for loop.
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
Difference between null pointer and dangling pointer?
Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates
What do the functions atoi(), itoa() and gcvt() do?
Define function pointers?
Is double link list a linear data structure? If Yes, Why?If No, Why?
Differentiate between functions getch() and getche().
a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above
what is the output of the code and how? main() { int *ptr,x; x=sizeof(ptr); printf("%d",x); }
read a number & print all its devisors using c-program?
What is memmove?
What is the difference between break and continue?
4. main() { int c=- -2; printf("c=%d",c); }