Saturday, April 2, 2016

Decision Making In C programming Language



Decision making structures are one the tools which gives C language its power. In these structure the programmer specifically defines one or more conditions what he wants to be evaluated or tested by the c program, given a statement or statements to be executed if the condition is becomes true, and optionally, other statements to be executed if the condition is false. In this C programming tutorial we using almost all decision making structures in the programs.
The generic form of a typical decision making structure in c language found in most of the programming language
When a programmer execute the c program, the statements are executed in sequence i.e. top to bottom order in which they appear in the C program. Usually Programmer may need a C language statement or a set of statements to be executed for a fixed no of times or until a condition becomes true moreover if a programmer may want to skip some statements based on testing a condition in C programming language. For all these we use conditional statements. Conditional statements are of two types
1 . Branching in C programming Language
2 . Looping in C programming
Branching:
If refers to execute one of several possible options depending on the outcome of a logic, which is carried at some specific point within a c program.
:Example:
Nested if-else statement
if – else statement with in other if – else statement. Such statements are called nested if statements in c programming language.
if (expression1)
{
Execute if expression1 is true;
}
else if( expression2)
{
Execute if expression1 is false and 2 is true;
}
else if (expression 3)
{
Execute if text expression1 and 2 are false and 3 is true;
}

Else
{
Execute if all of the expressions are false;
}
Looping: 
Looping in C programming language is used when one wants to execute a group of instructions repeatedly, a fixed no of times or until a specified condition is satisfied.
Example:
For (Age=0; Age<60; Age++)
{
Code to be executed;
}

0 comments:

Post a Comment