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

Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?

766


What do you mean by recursion in c?

849


What is assert and when would I use it?

759


What are pointers?

841


What does %p mean c?

813


Why do we use namespace feature?

802


Write a program which returns the first non repetitive character in the string?

811


Where static variables are stored in c?

777


Explain main function in c?

834


praagnovation

2004


What is the difference between test design and test case design?

1799


Is there any demerits of using pointer?

801


What are the ways to a null pointer can use in c programming language?

847


What is a void * in c?

827


How can you allocate arrays or structures bigger than 64K?

882