If with else - C Statement

C examples for Statement:if

Introduction

The else keyword is used in an if statement.

if(comparison)  
{  
        statement(s);  
}  
else  
{  
        statement(s);  
}  

else-if combination is used to allow the computer to accurately report whether the number is less than 5, equal to 5, or greater than 5:

Demo Code

#include <stdio.h>
#include <stdlib.h>
int main()//from   w w w  .  j  a va2  s .co  m
{
   char num[2];
   int number;
   printf("Enter a number from 0 to 9:");
   gets_s(num);
   number=atoi(num);
   if(number<5)
   {
      printf("That number is less than 5!\n");
   }
   else if(number==5)
   {
      printf("You typed in 5!\n");
   }
   else{
     printf("That number is more than 5!\n");
   }
return(0);
}

Result


Related Tutorials