Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

C programming if else if else statements

Posted on August 20, 2016November 28, 2025

Table of Contents

  • C programming  if else if else statements
      • Syntex for if…..  else
      • Syntex for if…..  else if ……else
    • Related

C programming  if else if else statements

In this tutorial, we will discuss the subject of C programming if else-if else statements
In this post, we are going to learn how to use if else-if else statements in C programming

first, The if statement evaluates the Boolean Expression inside the parenthesis. when the expression is evaluated to true(1), enter the body part and statements inside the body part of if are executed.

if the test expression is evaluated to false(0), The control is skipped the inside the body of statements from execution and exit from the if part

 

already we are learned the concept of the relational operator in the operator in C language to about understand boolean expression (test expression)

Syntex for if…..  else

if(boolean_expression) {
   /* statement(s) will execute if the boolean expression is true */
}
else {
   /* statement(s) will execute if the boolean expression is false */
}

Flow diagram of if statement

C programming  if else if else statements
If -else statements

/*

if(expression)
    {
    statement
    }else{
    statement;
    }

*/


program1

#include <stdio.h>
#include <stdlib.h>

int main()

    int age=20;
    if(age>=18)
    {
        printf("you are a minor");
    }
    else{

        printf("you are a adultn");
    }

    return 0;
}

When the code is executed, it produces the following result

C programming  if else if else statements
Program 1
program 2
#include <stdio.h>
#include <stdlib.h>


int main()
{
    /*local veriable definition*/
    int a=17;

    /*check the boolean condition*/
if(a<20)
{

    /*if condition is true then print the following*/
    printf("a is less than 20!n");

    }
    else{
         /*if condition is false then print the following*/
         printf("a is not less than 20!n");
    }

     printf("value of a is:%dn",a);
    return 0;
}

 

When the code is executed, it produces the following result
C programming  if else if else statements
program 2

Syntex for if…..  else if ……else

 

if(boolean_expression 1) {
   /* Executes when the boolean expression 1 is true */
}
else if( boolean_expression 2) {
   /* Executes when the boolean expression 2 is true */
}
else if( boolean_expression 3) {
   /* Executes when the boolean expression 3 is true */
}
else  {
   /* executes when the none of the above condition is true */
}
 
Program 3
 
#include <stdio.h>
#include <stdlib.h>

int main()
{
    /*local variable definition*/
    int a=25;

    /*local variable definition*/
    if(a==10){

        /*if condition is true then printing following*/
        printf("valeu of a is 10!n");
    }
    else if(a==20)
    {
        /*if condition is true then printing following*/
        printf("valeu of a is 20!n");
    }
    else if(a==30)
    {
        /*if condition is true then printing following*/
        printf("valeu of a is 30!n");
    }
    else
    {
        /*if condition is false then printing following*/
        printf("value is not matching!n");

    }
    printf("Exact value of a is:%d!n",a);
    return 0;
}

When the code is executed, it produces the following result

 
C programming  if else if else statements
program 3
Program 3
In the following program, the program allows the user to enter an integer number and checks the number for finding even or odd using the modular operator.
finally, it will be displayed given number is even or odd
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int number;
    printf("Enter an integer:");
    scanf("%d",&number);

    if(number%2==0)
    {
        printf("%d is an even integer.",number);
    }
        else
        {
            printf("%d is an odd integer.",number);
        }
return 0;
    }

When the code is executed, it produces the following result

C programming  if else if else statements
program 4
 
While Loop in Java      while Loop in C++     While Loop In C

Do-while Loop in Java    Do-while Loop C++      Do-while loop in C 

For Loop in C++       For Loop in C         For loop in java

If condition C++       If the condition in Java   If condition in C

Related

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes