GURU NANAK DEV CO-ED POLYTECHNIC

GURU NANAK DEV CO-ED POLYTECHNIC
MAIN BULIDING

Friday, 30 September 2011

Decision making statements


Decision making statements are used to skip or to execute a group of statements based on the result of some conditions. The decision making statements are,
            (i)         Simple if statement
            (ii)        if.......else statement
            (iii)       nested if
            (iv)       switch statement

(i)         Simple if statement
            The Simple if statement is used to execute or skip one statement or group of statements for a particular condition. The syntax is
                                    if(test condition)
                                                {
                                                            statement block;
                                                }
                                    next statement;

            When this statement is executed, the computer first evaluates the value of the test condition. If the value is true, statement block and next statement are executed sequentially. If the value is false, statement block is skipped and execution starts from next statement.
Conditions
(i)         The opening and closing curl brackets {} are must if the statement block
contains more than one statement.
(ii)        The brackets around the test condition are must
(iii)       The test condition must be relational or logical expression
(iv)       Statement block is called body of the if statement and it contains one or
more statement blocks.




#include<stdio.h>
            main( )
            {
                        int salary;
                        char good;
                        scanf (“%d %c”, &salary,&performance);
                        if (performance= =‘good’
                                    {
                                                salary=salary+1000;
                                    }
                                    printf(“%d”, salary)’
                        }
            This program tests the performance of an employee. If the performance of an employee in an organization is good, then Rs.1000/-  will be added to his salary. For other grades no incentives are added.