Instead of if/else statements, you can use the ternary operator:
#include <stdio.h>
int main() {
int num1, num2, num3, max;
if (scanf("%d%d%d", &num1, &num2, &num3) == 3) {
max = (num1 < num2) ? num1 : num2;
max = (max < num3) ? max : num3;
printf("%d\n", max);
}
return 0;
}
If the ternary operator is not allowed, you can use comparison operators, which may generate branchless code anyway:
#include <stdio.h>
int main() {
int num1, num2, num3, max;
if (scanf("%d%d%d", &num1, &num2, &num3) == 3) {
max = (num1 >= num2) * num1 + (num1 < num2) * num2;
max = (max >= num2) * max + (max < num2) * num2;
printf("%d\n", max);
}
return 0;
}
Note that you cannot use num1 + num2 nor num1 - num2, not even -num1 nor num2 because there operations may cause arithmetic overflow with undefined behavior.
Also note that you can abuse the rules by replacing if statements with while or for statements:
#include <stdio.h>
int main() {
int num1, num2, num3;
if (scanf("%d%d%d", &num1, &num2, &num3) == 3) {
for (max = num1; max < num2; max = num2)
continue;
while (max < num3)
max = num3;
printf("%d\n", max);
}
return 0;
}