Tutorials Point


  Learning C
  C Function References
  C Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     About TP     Advertising  
Latest C Tutorial

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");
  }
}

This will produce following result:

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


previous Printer Friendly

Advertisements


  

Advertisements