if...else if...else examples

« Previous

Try following example to understand if statement. You can put the following code into a test.c file and then compile it and then run it.

#include <stdio.h>
main()
{
  int cows = 6;
  if (cows > 1)
    printf("We have cows\n");
  if (cows > 10)
    printf("loads of them!\n");
  else
    printf("Executing else part...!\n");
  if (cows == 5 )
  {
    printf("We have 5 cows\n");
  }
  else if( (cows == 6 )
  {
    printf("We have 6 cows\n");
  }
}
                                        

Output Will Be :

We have cows
Executing else part...!
We have 6 cows
                            


« Previous
Have Any Suggestion? We Are Waiting To Hear from YOU!

Your Query was successfully sent!