在C语言中解释else-if梯形语句
这是编写多路决策的最通用方法。
语法
请参阅下面给出的语法 -
if (condition1) stmt1; else if (condition2) stmt2; - - - - - - - - - - else if (condition n) stmtn; else stmt x;
算法
参考下面给出的算法 −
START Step 1: Declare int variables. Step 2: Read a,b,c,d values at runtime Step 3: i. if(a>b && a>c && a>d) Print a is largest ii.else if(b>c && b>a && b>d) Print b is largest iii. else if(c>d && c>a && c>b) Print c is largest iv. else print d is largest STOP
示例
以下是执行Else If Ladder条件运算符的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 && a>c && a>d){ printf("%d is the largest",a); }else if(b>c && b>a && b>d){ printf("%d is the largest",b); }else if(c>d && c>a && c>b){ printf("%d is the largest",c); }else{ printf("%d is the largest",d); } }
输出
您将看到以下输出 −
Run 1:Enter the values of a,b,c,d: 2 4 6 8 8 is the largest Run 2: Enter the values of a,b,c,d: 23 12 56 23 56 is the largest
考虑另一个 C 程序,它使用 else ifladder 显示学生的成绩 -
实时演示
#include<stdio.h> int main(){ int marks; printf("Enter the marks of a student:</p><p>"); scanf("%d",&marks); if(marks <=100 && marks >= 90) printf("Grade=A"); else if(marks < 90 && marks>= 80) printf("Grade=B"); else if(marks < 80 && marks >= 70) printf("Grade=C"); else if(marks < 70 && marks >= 60) printf("Grade=D"); else if(marks < 60 && marks > 50) printf("Grade=E"); else if(marks == 50) printf("Grade=F"); else if(marks < 50 && marks >= 0) printf("Fail"); else printf("Enter a valid score between 0 and 100"); return 0; }
输出
您将看到以下输出 −
Run 1: Enter the marks of a student:78 Grade=C Run 2: Enter the marks of a student:98 Grade=A
以上是在C语言中解释else-if梯形语句的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

Gulc是一个高性能的C库,优先考虑最小开销,积极的内衬和编译器优化。 其设计非常适合高频交易和嵌入式系统等关键应用程序,其设计强调简单性,模型

本文详细介绍了C函数返回类型,包括基本(int,float,char等),派生(数组,指针,结构)和void类型。 编译器通过函数声明和返回语句确定返回类型,执行

本文解释了C函数声明与定义,参数传递(按值和指针),返回值以及常见的陷阱,例如内存泄漏和类型不匹配。 它强调了声明对模块化和省份的重要性

本文详细介绍了字符串案例转换的C功能。 它可以通过ctype.h的toupper()和tolower()解释,并通过字符串迭代并处理零终端。 常见的陷阱,例如忘记ctype.h和修改字符串文字是

本文研究C函数返回值存储。 较小的返回值通常存储在寄存器中以备速度;较大的值可能会使用指针来记忆(堆栈或堆),影响寿命并需要手动内存管理。直接ACC

本文分析了形容词“独特”的多方面用途,探索其语法功能,常见的短语(例如,“不同于”,“完全不同”),以及在正式与非正式中的细微应用

本文解释了C标准模板库(STL),重点关注其核心组件:容器,迭代器,算法和函子。 它详细介绍了这些如何交互以启用通用编程,提高代码效率和可读性t

本文详细介绍了c中有效的STL算法用法。 它强调了数据结构选择(向量与列表),算法复杂性分析(例如,std :: sort vs. std vs. std :: partial_sort),迭代器用法和并行执行。 常见的陷阱
