Using nested ifs : If statement « Statement « C Tutorial






#include <stdio.h>
#include <limits.h>

int main(void)
{
  long test = 0L;              


  if( test % 2L == 0L) {
    printf("The number %ld is even", test);

    if ( (test/2L) % 2L == 0L)
    {
      printf("\nHalf of %ld is also even", test);
      printf("\nThat's interesting isn't it?\n");
    }
  }
  else
    printf("The number %ld is odd\n", test);
  return 0;
}
The number 0 is even
     Half of 0 is also even
     That's interesting isn't it?








6.3.If statement
6.3.1.if statement
6.3.2.To execute only one statement, opening and closing braces are not required
6.3.3.The if statement: a compound statement
6.3.4.If with else statement
6.3.5.The if-else-if statement
6.3.6.if statement with two else statements
6.3.7.if statement: compare the value from user input
6.3.8.Using nested ifs
6.3.9.Use compound conditions to check for upper and lowercase letters
6.3.10.Checking for a Range of Values
6.3.11.Use isdigit Function in if statement
6.3.12.Operators Used in if Comparisons
6.3.13.if Comparisons and Their Opposites