how to find the largest element of array without using relational operater?
Answers were Sorted based on User's Feedback
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 |
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 |
Answer / s.gayathri
using conditional operator we do that operation
Is This Answer Correct ? | 3 Yes | 3 No |
/*
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 |
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 |
Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
What is the advantage of a random access file?
Write a program in c to print * * * * * *******
What are the 4 types of organizational structures?
What is an array? What the different types of arrays in c?
what will be the output off the following program? #include<stdio.h> int main() { int a; a=015+0*71+5; printf("%d,a"); return0; }
what is the output of following question? void main() { int i=0,a[3]; a[i]=i++; printf("%d",a[i] }
What should malloc(0) do?
There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?
What is the difference between char a[] = "string"; and char *p = "string"; ?
14 Answers Adobe, Honeywell, TCS,
What is use of bit field?
tell me the full form of c?