Compter pogramming and utilization

33
COMPTER POGRAMMING AND UTILIZATION CONTROL STRUCTURES IN ‘C’ GUIDED BY: Prof. Parin Patel

Transcript of Compter pogramming and utilization

Page 1: Compter pogramming and utilization

COMPTER POGRAMMING AND UTILIZATION

CONTROL STRUCTURES IN ‘C’

GUIDED BY: Prof. Parin Patel

Page 2: Compter pogramming and utilization

GROUP MEMBERSNAME

RAJPUT ROHANSHARMA MAULIKSINGH DEVANSHSINGH UDDESHYA

Page 3: Compter pogramming and utilization

CONTENTS Introduction If Statement Simple if Statement If….else Statement Nested if Statement The Else If Ladder The Switch Statement The ?:operator The GOTO Statement The while Statement The do Statement The for Statement

Page 4: Compter pogramming and utilization

INTRODUCTION DECISION MAKING In bank, if we want to withdraw money, there

should be enough bank balance. So certain actions can take place if specific conditions are satisfied. This is called decision making.

C language supports following statements for decision making capability.

1. If statement2. Switch statement3. Conditional operator statement4. Goto statement

Page 5: Compter pogramming and utilization

1.IF STATEMENT The if statement is a powerful decision

making statement and is used to control the flow of execution of statements.

It is basically a two way decision statement and is used in conjuction with an expression.

General form if(expression) Statement(s);

Page 6: Compter pogramming and utilization

FLOW CHART OF IF CONTROL

Page 7: Compter pogramming and utilization

EXAMPLE OF IF CONTROL

Page 8: Compter pogramming and utilization

2.SIMPLE IF STATEMENT General form if (test expression) { statement-block; } statement x;

Page 9: Compter pogramming and utilization

FLOW CHART OF SIMPLE IF CONTROL

Page 10: Compter pogramming and utilization

EXAMPLE OF SIMPLE IF CONTROL

Page 11: Compter pogramming and utilization

3.IF….ELSE STATEMENT The if….else statement is an extension of the simple if

statement. General form if (test expression) { true-block statement(s) } else { false-block statement(s) } statement x

Page 12: Compter pogramming and utilization

FLOW CHART OF IF….ELSE CONTROL

Page 13: Compter pogramming and utilization

EXAMPLE OF IF….ELSE CONTROL

Page 14: Compter pogramming and utilization

4.NESTED IF STATEMENT General form if (test condition-1) { if (test-condition-2); { statement-1; } else { statement-2; } } else { statement-3; } statement-x;

Page 15: Compter pogramming and utilization

FLOW CHART OF NESTED IF STATEMENT

Page 16: Compter pogramming and utilization

EXAMPLE OF NESTED IF STATEMENT

Page 17: Compter pogramming and utilization

5.THE ELSE IF LADDER General form if (condition 1) statement-1; else if (condition 2) statement-2; else if (condition 3) statement-3; else if (condition n) statement-n; else default statement; statement-x;

Page 18: Compter pogramming and utilization

FLOW CHART OF ELSE….IF LADDER

Page 19: Compter pogramming and utilization

EXAMPLE OF ELSE….IF LADDER

Page 20: Compter pogramming and utilization

6.THE SWITCH STATEMENT General form switch (expression) { case value-1: block-1 break; case value-2: block-2 breal; …………….. …………….. default: default-block break; } statement-x;

Page 21: Compter pogramming and utilization

SELECTION PROCESS OF SWITCH STATEMENT

Page 22: Compter pogramming and utilization

EXAMPLE OF SWITCH STATEMENT

Page 23: Compter pogramming and utilization

7.THE?: OPERATOR The ?: operator is used to make two way

decision. General form conditional expression?

expression1:expression2

Page 24: Compter pogramming and utilization

EXAMPLE OF ?: OPERATOR

Page 25: Compter pogramming and utilization

8.THE GOTO STATEMENT In “C” language goto statement is used to jump unconditionally from one point to another in

the same program. The goto statement requires a label. General form (forward jump) goto skip; …………….. …………….. …………….. skip: statement;

(backward jump) skip: statement; …………….. …………….. …………….. goto skip;

Page 26: Compter pogramming and utilization

EXAMPLE OF GOTO STATEMENT

Page 27: Compter pogramming and utilization

9.THE WHILE STATEMENT The simplest of the looping structures in

C is the while statement. The while is an entry-controlled loop statement.

General form while (test condition) { body of the loop }

Page 28: Compter pogramming and utilization

EXAMPLE OF WHILE STATEMENT

Page 29: Compter pogramming and utilization

10.THE DO STATEMENT In certain situations, it is necessary to execute

the body of the loop at least once and then condition should be tested. In that situation do statement is used.

General form do { statement block; } while(condition);

Page 30: Compter pogramming and utilization

EXAMPLE OF DO STATEMENT

Page 31: Compter pogramming and utilization

11.THE FOR STATEMENT The for statement for loop is used to

repeatedly execute statement or block of statements fixed numbers of times.

General form for (initialization;test-

condition;increment) { body of the loop }

Page 32: Compter pogramming and utilization

EXAMPLE OF FOR STATEMENT

Page 33: Compter pogramming and utilization