Tuesday 26 October 2010

if statement


The if statement checks whether the text expression inside parenthesis ( ) is true or not. If the test expression is true, statement/s inside the body of if statement is executed but if test is false, statement/s inside body of if is ignored.



Syntax:
          if(condition)
         {
            Statement1;
          }
         else
         {
           Statement2;
          }


If given condition is TRUE, statement1 will get executed.
If given condition is FALSE (not TRUE), statement2 will get executed.

//wap to find out the largest of two nos
#include<stdio.h>
#include<conio.h>

void main()
{
 int x,y;
 clrscr();
 printf("Enter value for x and y:");
 scanf("%d%d",&x,&y);
 if ( x > y )
 {
  printf("X is large number - %d\n",x);
 }
 else
 {
  printf("Y is large number - %d\n",y);
 }
 getch();
}
Conditional statements

No comments:

Post a Comment