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

Answers were Sorted based on User's Feedback



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

Answer / icywind

#include <stdio.h>
#define SIZE 5
int main(void)
{

int array[] = {100, 32, 22, 500, 21};
int max=0,ii;

for( ii = 0; ii<SIZE; ii++)
{
max = (array[ii]>max)?array[ii]:max;
}
printf("max = %d\n", max);
return 0;
}

Is This Answer Correct ?    7 Yes 1 No

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

Answer / 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

More C Interview Questions

what would be the output of the follwing struct st { char name[20]; int i; float f; }; main() { struct st emp = {"forum"}; printf("%d %f",emp.i,emp.f); }

4 Answers  


If 4 digits number is input through the keyboard, Write a program to calculate sum of its 1st & 4th digit.

12 Answers   Google,


Do you know the use of 'auto' keyword?

0 Answers  


What is the output of below code? main() { static in a=5; printf("%3d",a--); if(a) main(); }

4 Answers   Infosys, TCS,


illustrate the use of address operator and dereferencing operator with the help of a program guys plzzz help for this question

0 Answers  






#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }

0 Answers   Wilco,


What is a string?

0 Answers  


When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?

0 Answers   TISL,


please give code for this 1 2 4 7 11 16

11 Answers   Intel, Wipro,


Describe newline escape sequence with a sample program?

0 Answers  


Write a C/C++ program that connects to a MySQL server and checks intrusion attempts every 5 minutes. If an intrusion attempt is detected beep the internal speaker to alert the administrator. A high number of aborted connects to MySQL at a point in time may be used as a basis of an intrusion.

1 Answers  


how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?

0 Answers   TCS,


Categories