how to find the largest element of array without using relational operater?

Answers were Sorted based on User's Feedback



how to find the largest element of array without using relational operater?..

Answer / upendra singh and avinash cho

#include<stdio.h>
#include<string.h>
void main()
{
int arr[4]={1,10,5,4},c,i,k,j=1;
k=arr[0];
for( i=0;i<3;i++)
{ c=k-arr[i+1];
c=c>>15;
if(c)
k=arr[i+1];
}
printf("largest number %d",k);
getch();
}

Is This Answer Correct ?    25 Yes 11 No

how to find the largest element of array without using relational operater?..

Answer / mpasinski

Regarding Answer2 - what if int in your machine is 32 bit
instead of 16. The code is not universal.

Is This Answer Correct ?    4 Yes 1 No

how to find the largest element of array without using relational operater?..

Answer / s.gayathri

using conditional operator we do that operation

Is This Answer Correct ?    3 Yes 3 No

how to find the largest element of array without using relational operater?..

Answer / hari

/*
find a largest number out of an given array without
using relational operators
*/

#include<stdio.h>
int f(int m,int n)
{if(!(m/n)) return n;

else return m;
}

int main()
{
int a[100],n=0,i,j;
scanf("%d",&n); // length of array (max 100)
for( i=0;i<n;i++)
scanf("%d",&a[i]);
int s=a[0];
a[n+1]=0;
for( j=1;j<n;j++)
{
if(f(a[j],s))
s=a[j];
}
printf("%d",s);
return 0;
}



for further queries and discussions, just check these out !!!

http://forum.campusmaniac.com/
http://www.campusmaniac.com/

Is This Answer Correct ?    1 Yes 2 No

how to find the largest element of array without using relational operater?..

Answer / dhakchina moorthy.p

sort the array first and then have the last element of the
array, which is always larger then the remaining.

Is This Answer Correct ?    0 Yes 2 No

how to find the largest element of array without using relational operater?..

Answer / bkushwaha89

code and explation.

Is This Answer Correct ?    7 Yes 14 No

Post New Answer

More C Interview Questions

write a c program in such a way that if we enter the today date the output should be next day's date.

0 Answers  


write a c program to find largest number in matrix(in each row,each column, diagonally, and in the whole matrix)? Its urgent.

2 Answers  


Explain what will the preprocessor do for a program?

0 Answers  


What is the difference between malloc calloc and realloc in c?

0 Answers  


what is the c source code for the below output? 10 10 10 10 10 10 10 10 10 10 9 9 7 6 6 6 6 6 6 9 7 5 9 7 3 2 2 5 9 7 3 1 5 9 7 3 5 9 7 4 4 4 4 5 9 7 8 8 8 8 8 8 8 8 9

0 Answers  






What is the difference between formatted&unformatted i/o functions?

0 Answers  


What is the output of the program #include<stdio.h> #include<conio.h> void main() {0 int i,j=20; clrscr(); for(i=1;i<3;i++) { printf("%d,",i); continue; printf("%d",j); break; } getch(); }

4 Answers   CTS, Oracle,


write a program to print the all 4digits numbers & whose squares must me even numbers?

2 Answers   Virtusa,


is it possible to create your own header files?

0 Answers  


Find MAXIMUM of three distinct integers using a single C statement

0 Answers  


print out put like this form 1 2 3 4 5 6 3 5 7 9 11 8 12 16 20

8 Answers   TCS,


What is the purpose of clrscr () printf () and getch ()?

0 Answers  


Categories