else - 如果梯子是编写多路决策的最通用方式。
else if 梯子的语法如下 -
if (condition1) stmt1; else if (condition2) stmt2; - - - - - - - - - - else if (condition n) stmtn; else stmt x;
请参阅下面给出的流程图 -
以下是执行 Else If Ladder 条件语句的 C 程序 -
立即学习“C语言免费学习笔记(深入)”;
现场演示
#include<stdio.h> void main (){ int a,b,c,d; printf("Enter the values of a,b,c,d: "); scanf("%d%d%d%d",&a,&b,&c,&d); if(a>b){ printf("%d is the largest",a); } else if(b>c){ printf("%d is the largest",b); } else if(c>d){ printf("%d is the largest",c); } else{ printf("%d is the largest",d); } }
当执行上述程序时,会产生以下结果 -
Enter the values of a,b,c,d: 2 3 4 5 5 is the largest
以上就是如何在C语言中使用“else if ladder”条件语句?的详细内容,更多请关注php中文网其它相关文章!
C语言怎么学习?C语言怎么入门?C语言在哪学?C语言怎么学才快?不用担心,这里为大家提供了C语言速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号