Yesterday I went for an interview where I have been asked to create a program to find largest and smallest among 5 numbers without using array.
I know how to create
Here's my implementation: Simple and short
#include
#include
using namespace std;
int max_of_five(int a, int b, int c, int d,int e){
int large= max(max(a, b), max(c,d));
return max(large,e);
}
int min_of_five(int a,int b,int c, int d,int e){
int small=min(min(a,b),min(c,d));
return min(small,e);
}
int main() {
int a, b, c, d,e;
scanf("%d %d %d %d %d", &a, &b, &c, &d,&e);
int ans = max_of_five(a, b, c, d, e);
int ans1=min_of_five(a,b,c,d,e);
printf("Max:\t%d\n", ans);
printf("Min:\t%d", ans1);
return 0;
}