C Decision Making - Branching

if Statement

The simplest form of the control statement is the If statement.It is very frequently used in decision making and allowing the flow of program execution.

The statement is any valid C’ language statement and the condition is any valid C’ language expression, frequently logical operators are used in the condition statement.
The condition part should not end with a semicolon, since the condition and statement should be put together as a single statement.

Program for if statement

	#include ' stdio.h '
    void main ( ) 
	   int numbers; 
	   printf (“Type a number:”); // message to the user 
	   scanf (“%d”, & number);  // read number from standard input 
	   if (number < 0)    // check whether number is negative //number 
	   number = - number;   // If negative, convert it into //positive. 
	   Printf (“The absolute value is %d \n”,number);   //print value

Program description

The above program checks the value of the input number to see if it is less than zero.
If it is then the following program statement which negates the value of the number is executed.
If the value of the number is not less than zero, we do not want to negate it then this statement is automatically skipped. The absolute number is then displayed by the program, and program execution ends.


Make Comments..!!

Oops!! No posts from user.

Download Android App