C语言流程控制语句 |
您所在的位置:网站首页 › c语言程序4个步骤怎么表示 › C语言流程控制语句 |
循环控制语句
C语言有3种循环 forwhiledo while while循环我们先来看下while循环,流程图如下: 流程图如下: 流程图如下: 接下来看一个for循环的示例 我们先来看个简单的示例: #define _CRT_SECURE_NO_WARNINGS #include int main() { int score; printf("请输入学生的数学成绩:"); scanf("%d", &score); if (score = 0) { printf("该学生的数学成绩类别为:差\n"); } else if (score = 60) { printf("该学生的数学成绩类别为:及格\n"); } else if (score = 70) { printf("该学生的数学成绩类别为:中\n"); } else if (score = 80) { printf("该学生的数学成绩类别为:良\n"); } else if (score = 90) { printf("该学生的数学成绩类别为:优\n"); } return 0; }
if语句流程图如下 求a,b,c三个数中的最大值? #define _CRT_SECURE_NO_WARNINGS #include int main() { int a, b, c; int max1, max2; a = 8; b = 12; c = 10; if (a>b) { if (a>c) { max1 = a; } else { max1 = c; } } else { if (b>c) { max1 = b; } else { max1 = c; } } //三元表达式 max2 = a > b ? (a > c ? a : c) : (b > c ? b : c); printf("the max number is %d\n", max1); printf("the max number is %d\n", max2); return 0; }结果 |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |