if(boolean_expression 1) {
/* Executes when the boolean expression 1 is true */
}
else if( boolean_expression 2) {
/* Executes when the boolean expression 2 is true */
}
else if( boolean_expression 3) {
/* Executes when the boolean expression 3 is true */
}
else {
/* executes when the none of the above condition is true */
}
[dywang@deyu zzz]$ vim if4.c
[dywang@deyu zzz]$ cat if4.c
#include <stdio.h>
int main() {
int a;
printf("Enter an integer: ");
scanf("%d", &a);
if ( a>10 ) {
printf("%d > 10\n", a);
}
else if ( a<10) {
printf("%d < 10\n", a);
}
else {
printf("a = 10\n");
}
}
[dywang@deyu zzz]$ gcc -o if4 if4.c
[dywang@deyu zzz]$ ./if4 Enter an integer: 20 20 > 10
[dywang@deyu zzz]$ ./if4 Enter an integer: 8 8 < 10
[dywang@deyu zzz]$ ./if4 Enter an integer: 10 a = 10