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 is the explanation for the dangling pointer in c?

683


Explain the difference between call by value and call by reference in c language?

648


Explain zero based addressing.

610


What are structure members?

600


What is const volatile variable in c?

579






Differentiate between #include<...> and #include '...'

617


How many levels of indirection in pointers can you have in a single declaration?

596


Why n++ execute faster than n+1 ?

1852


WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?

1860


process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,

1893


write a progrmm in c language take user interface generate table using for loop?

1575


When can a far pointer be used?

589


Which is best book for data structures in c?

599


How do I convert a string to all upper or lower case?

630


Write a program to reverse a given number in c?

602