Given 4 integers, find the smallest. --try to minimize the number of comparisons
ID: 3642129 • Letter: G
Question
Given 4 integers, find the smallest. --try to minimize the number of comparisons, and not repeat comparison. Hint: Use an extra variable to store partial results#include <stdio.h>
int main(void){
int a, b, c, d;
printf("Please enter 4 numbers separated by spaces > ");
scanf("%d%d%d%d",&a,&b,&c,&d");
if(a>b)
a=b;
if(a>c)
a=c;
if(a>d)
a=d;
printf("%d is the smallest",a);
return(0);
}
What's wrong with the codes?
Thanks in advance.