C program to study the Conditional Statements
C program to study conditional statement
by Krishna viswambharan
Posted on 24 Aug 2017 Category: C
Edited on 25 Aug 2017
C program to find largest among two numbers using 'if-else' conditional statement
This article explains various conditional statements in C language with sample programs. Conditional statements in C language are given as below
- If statement
- If –Else statement
- Nested If-else statement
- Switch statement
These are also called branching statements because it can jump from a particular block of a program to another block based on whether a particular condition is satisfied or not.
Selection with ‘If’ Statement
This is the simplest decision making statement in C language. It allows the machine to compute the expression depending on the value of the expression is ‘true’ or ‘false’.
The syntax is given as follows :-
Selection with ‘If-Else’ Statement
We can say that ‘if-else’ is an extension of ‘if’ statement. The syntax is given as
True block statement(s);
false block statement(s);
If the test condition is true , then the true block of statements will execute and if the condition is false the control goes to else part and execute the false-block of statements.
The program given below is an example of ‘ if-else’ control flow. Let us see how it works.
printf(“enter the first number :”);
printf(“enter the second number :”);
printf(“%d is the largest number”,n1);
printf(“%d is the largest number”,n2);