










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth explanation of selection structures in c programming, focusing on the use of if, else if, and else statements. Selection structures enable programmers to make decisions based on logical expressions and execute alternate actions accordingly. The syntax and usage of single-selection, double-selection, and nested if/else structures, as well as examples of simple and complex programs.
Typology: Slides
1 / 18
This page cannot be seen from the preview
Don't miss anything!











If you can keep your head when all about you Are losing theirs and blaming it on you, If you can trust yourself when all men doubt you But make allowance for their doubting too, If you can wait and not be tired by waiting, Or being lied about, don't deal in lies, Or being hated, don't give way to hating, And yet don't look too good, nor talk too wise: THEN Yours is the Earth and everything that's in it, And--which is more--you'll be a Man, my son! --Rudyard Kipling
if / else if / else Selection
Structures
if ( this logical expression is true ) statement ;
if ( this logical expression is true ) statement ;
else statement ;
if ( this logical expression is true ) statement ;
if ( this logical expression is true ) statement ; else statement ;
no semi-colon!
#include <stdio.h> int main ( ) { int a = 1, b = 2, c ; if (a > b) c = a ; else c = b ; }
if / else if / else Selection Structures
if (score >= 90) printf ("Your score of %d is a A\n", score) ; else if (score >= 80 && score < 90) printf ("Your score of %d is a B\n", score) ; else if (score >= 70) printf ("Your score of %d is a C\n", score) ; else if (score >= 60) printf ("Your score of %d is a D\n", score) ; else printf ("Your score of %d is an E\n", score) ;
}