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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the disadvantages of c language?

610


How can I make it pause before closing the program output window?

565


When should volatile modifier be used?

543


What is the use of linkage in c language?

604


how to find anagram without using string functions using only loops in c programming

2708






To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9

2177


How can I delete a file?

621


I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...

9647


Explain how do you use a pointer to a function?

631


What is binary tree in c?

617


What is static and volatile in c?

773


What is file in c language?

569


If the size of int data type is two bytes, what is the range of signed int data type?

581


Why isn't any of this standardized in c? Any real program has to do some of these things.

615


What is the most efficient way to store flag values?

676