Skip to main content

another example of if-else-if ladder in C

#include<stdio.h>
int main()
{
   int age;
   printf("Enter your age\n");
   scanf("%d",&age);
   if (age>=18)
   {
      printf("you can vote");
   }
   else if (age<14)
   {
      printf("you can vote for kids");
   }
   else
   {
      printf("you can,t vote sorry!");
   }
   
   
   return 0;
}


//we can also do like this
#include<stdio.h>
int main()
{
   int age;
   printf("Enter your age\n");
   scanf("%d",&age);
   if (age>=18)
   {
      printf("you can vote");
   }
   else if (age==1,2,3,4,5,6,7,8,9,10,11,12,13,14)
   {
      printf("you can vote for kids");
   }
   else
   {
      printf("you can,t vote sorry!");
   }
   
   
   return 0;
}


Comments

Popular posts from this blog

example of typecasting in c

/*Type Casting in C Typecasting allows us to convert one data type into other. */ //simple example to cast int value into the float. #include <stdio.h>    int   main (){   float   f = ( float ) 9 / 4 ;     printf ( "f : %f \n " ,  f  );     return   0 ;   }