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
Why is c still so popular?
Is javascript based on c?
The file stdio.h, what does it contain?
Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
Why header files are used?
Write a c program to build a heap method using Pointer to function and pointer to structure ?
What is your stream meaning?
What is use of null pointer in c?
What is the explanation for cyclic nature of data types in c?
What is the difference between functions abs() and fabs()?
What are the disadvantages of external storage class?
int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above
What is the purpose of sprintf() function?
When can you use a pointer with a function?
Compare and contrast compilers from interpreters.