Conditional Statements in C (if, if…else, else if, nested if, switch case)

Conditional Statements in C (if, if…else, else if, nested if, switch case)



Control Statements In C

Control Statements are used to ramdom execution of the program .In C lamguage these are classified into following types.

1.Conditional Statements
2.Looping Statements
3.Unconditional Statements

Conditional Statements
Conditional statements are used check the condition whether it is true or false.
In java language these opeatrs are classified into following types.

1.if condition
2.if else condition
3.else if condition
4.nested if condition
5.switch expression

if condition
'if' is a keyword in java language .Which is used to execute one block of statements by negleting some other statements.
Syntax:
if(Condition)
{
    statement 1
    statement 2
    ..
    ..
}
In the above syntax 'if' condition is true the statements of 'if' block is execute.'if' the condition is false program terminated.

if else condition
'if else' is a keyword in java language .Which is used to execute one block of statements between two blocks
Syntax:
if(Condition)
{
    statement 1
    statement 2
    ..
    ..
}
else
{
    statement 3
    statement 4
    ..
    ..
}
In the above syntax 'if' condition is true the statements of 'if' block is execute.'if' the condition is false the statements of 'else' block is execute.

Write a C-program to print ODD or Even Number using if else condition

#include <stdio.h>
                                                                         
int main() {
    int x;
    printf("Enter x value");
    scanf("%d",&x);
    if(x%2==0)
    {
        printf("Even is Nnumber");
    }
    else
    {
        printf("Odd is Number");
    }
    
    return 0;
}
                                            

Output:

Enter x value 10
Even Number

Enter x value 11
Odd Number


More Programs

Write a C-program to print ODD or Even Number using if else condition

Write a C-program to print max number using if else condition

Write a C-program to check the given number is valid or invalid(value must divisible by 2 and 3)

Write a C-program to check the given number is valid or invalid(value must divisible by 2 and 3 not 4)

Write a C-program to check the given number is valid or invalid(value must divisible by 2 and 3 not 4 using 2 conditions)

Write a C-program to check the given number is valid or invalid(value must between 20 and 30)

Write a C-program to check the given character is vowel or consonant

Write a C-program to check the given character is small letter or not

Write a C-program to check the given character is capital letter or not

Write a C-program to check the given character is number or not

Write a C-program to check the given character is symbol letter or not

Write a C-program to calculate simple interest with following conditions