Movatterモバイル変換


[0]ホーム

URL:


C else-if Statements

C Programming Tutorials

Overview of C LanguageC Language FundamentalsData Input and OutputDecision Control StatementsLoop Control StatementsFunctionsPreprocessors and Header FilesArrays and StringsPointersStructure and UnionFile Handling

C "else-if statements" is like another if condition; it's used in a program when an "if statement" has a probability of multiple decisions.

The basic format of the else if statement is:

Syntax:

if(test_expression){    //execute your code}else if(test_expression n){   //execute your code}else{   //execute your code}

Example of a C Program to Demonstrate else if Statement

Example:

#include<stdio.h>void main(){  int a, b;  printf("Please enter the value for a:");  scanf("%d", &a);  printf("\nPlease enter the value for b:");  scanf("%d", &b);  if (a > b)  {    printf("\n a is greater than b");  }  else if (b > a)  {    printf("\n b is greater than a");  }  else  {    printf("\n Both are equal");  }}

Program Output:

c-else-if

c-else-if-1

else if Statements in C - Video Tutorial

Please watch this video tutorial to understand "C else-if Statements" in more depth.



Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram

[8]ページ先頭

©2009-2025 Movatter.jp