This blog is under construction

Saturday 21 April 2012

Control statements - if-else Statement

Syntax for if-else statement:

if (expression) {
     <IF BLOCK>
} else {
     <ELSE BLOCK>
}

If the truth value of the expression is evaluated to be true, then the statements present inside the IF BLOCK would get executed.  Otherwise, the statements present inside ELSE BLOCK would get executed.

Example program for if-else statement:
  #include <stdio.h>
  int main() {
        int data;
        printf("Enter a number:");
        scanf("%d", &data);
        // check whether the value of data is greater than 100
        if (data > 100) {
                // if block
                printf("Entered no is greater than 100\n");
        } else {
                // else block
                printf("Entered no is not greater than 100\n");
        }
        return 0;
  }


  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter a number:156
  Entered no is greater than 100



2 comments:

  1. Thanks For this Article.This is very helpful for me.Students who need more information about this topics, They can checkout Maxlearners for free.

    ReplyDelete
  2. Dell Laptop Service center are giving repair service at the door. We should high quality Dell out of warranty Laptop Repair, removal of virus, screen removal, wireless network set up, battery removal, motherboard replacement to several other are offered at budget friendly price and it’s Negotiable. We can fix them all in time by our well experience and certified technicians. If you want to repair your laptop in front of your eyesight, than you may call us: 7217871051

    ReplyDelete