Example if
/else
, if.c:
#include <stdio.h>
main() {
int number;
printf ("Enter a magical number: ");
scanf ("%d", &number);
if (number >= 100) {
printf ("Your number is very magical! \n");
} else {
printf ("Your number needs more magic :( \n");
}
}
Things to note:
condition
to test whether things are true
or false
condition
is a boolean expression (or function) that returns true
or false
true
block of codecondition
is true
false
block of codecondition
is false
if
/else
control statement