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, 2016January 29, 2020

Table of Contents

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

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


/*

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

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

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

 
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

 
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

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes