Exercise: Write a C program, input three values a, b, and c, and output the largest of them
code:
#include<stdio.h>
int main()
{
int a,b,c,max;
printf("请输入三个数a,b,c\n");
scanf("%d %d %d",&a,&b,&c);
if (a>b) //注意if后的判断语句写在括号内
{
if (c>a)
max=c;
else //包括c=a的情况
max=a;
}
else
{
if (c>b)
max=c;
else
max=b;
}
printf("三个数中最大的是%d",max);
return 0;
}
Points to note:
①The judgment statement after the if is written in brackets (that is, pay attention to the format of the if else statement)
②It is not necessary to list the cases where two numbers are equal (or three numbers are equal), if they are the same, you can use the same letter represent the number.