If-Else Introduction Week 1
If-Else Introduction Week 1
Week 1
Statements and Blocks
¢An expression such as x=0 or printf(…) becomes a
statement when it is followed by a semi-colon, as in
x = 0;
printf( … );
# include <stdio.h>
main() {
int x; int y;
scanf( “%d%d”, &x, &y );
if (x < y) 1. Checks if x is less
printf(“%d”,x); than y.
else 2. If so, print x
printf(“%d”, y); 3. Otherwise, print y.
}
if (expression)
statement1
statement2
“The instructor of this course owns the copyright of all the course materials. This lecture
material was distributed only to the students attending the course ESC-101 of IIT
Kanpur and should not be distributed in print or through electronic media without the
consent of the instructor. Students can make their own copies of the course materials
for their use.”