零基础学习c语言|5、分支结构之if语句
1、if语句(1)
代码示例
#include <stdio.h>
int main()
{
int age;
printf("请用户输入您的年龄:");
scanf("%d", &age);
if (age >= 18)
{
printf("您的年龄符合要求");
}
return 0;
}
运行结果
2、if语句(2)
代码示例
#include <stdio.h>
int main()
{
int age;
printf("请用户输入您的年龄:");
scanf("%d", &age);
if (age >= 18)
{
printf("您的年龄符合要求");
}
else
{
printf("您的年龄不符合要求");
}
return 0;
}
运行结果
3、if语句(3)
代码示例
#include <stdio.h>
int main()
{
int score;
printf("请学生输入你的成绩:");
scanf("%d", &score);
if (score >= 90 && score <= 100)
{
printf("非常优秀");
}
else if (score < 90 && score >= 80)
{
printf("优秀");
}
else if (score < 80 && score >= 70)
{
printf("良好");
}
else if (score < 70 && score >= 60)
{
printf("及格");
}
else
{
printf("不及格");
}
return 0;
}
运行结果