suppose there are five integers write a program to find
larger among them without using if- else

Answer Posted / brindha

#define<stdio.h>
void main()
{
int num, max = 0;
for (i = 0;i < 5; i ++)
{
scanf("Enter next number: %d", &num);
max = findMax(max, num);
}
printf(" MAX is %d", max);
}

int findMax(int x, int y)
{
int mask = 0, result;
mask = (x - y) >> 31;
result = (~mask & x) | (mask & y);
return result;
}

Is This Answer Correct ?    0 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is swift based on c?

624


What is a sequential access file?

643


What is void c?

558


If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?

770


What is register variable in c language?

590






Do you know null pointer?

596


Using which language Test cases are added in .ptu file of RTRT unit testing???

3573


What standard functions are available to manipulate strings?

552


explain how do you use macro?

655


Is fortran faster than c?

570


Is c still used?

591


Write a program in "C" to calculate the root of a quadratic equation ax^2+bx+c=0, where the value of a,b & c are known.

1716


Why #include is used in c language?

584


What is the deal on sprintf_s return value?

631


Write the Program to reverse a string using pointers.

609