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

find the output? void r(int a[],int c, int n) { if(c>n) { a[c]=a[c]+c; r(a,++c,n); r(a,++c,n); } } int main() { int i,a[5]={0}; r(a,0,5); for(i=0;i<5;i++) printf("\n %d",a[i]); getch(); }

2068


I need a sort of an approximate strcmp routine?

832


State the difference between x3 and x[3].

837


any "C" function by default returns an a) int value b) float value c) char value d) a & b

863


What are the 4 types of organizational structures?

822


How to draw the flowchart for structure programs?

8974


Can you subtract pointers from each other? Why would you?

746


Do you know the use of 'auto' keyword?

866


Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop

1916


If one class contains another class as a member, in what order are the two class constructors called a) Constructor for the member class is called first b) Constructor for the member class is called second c) Only one of the constructors is called d) all of the above

827


Why is sprintf unsafe?

809


Write a program to print ASCII code for a given digit.

887


Explain how can I read and write comma-delimited text?

929


What are qualifiers in c?

772


Why do some versions of toupper act strangely if given an upper-case letter?

834