An effective way to use of Else If

0 Suresh Chand June 2, 2021

In this program, We will learn to use of else if condition in effective way. For this we will take an example to check number is less thank 50 or not. To understand this example, You must have knowledge in following topics

Download Application: Learn C Programming with Live Compiler

In this example, We will take integer input from user and store in variable and check whether number is less than 50 or not.

Algorithm

This is the algorithm to check whether number is less than 50 or not

Step 1: Start

Step 2: Initialize integer variable as the number

Step 3: Read integer variable and store in number

Step 4: IF number < 50

           Step 4.1 : Number is less than 50

Step 5: Else

         step 5.1: Number is greater than 50

Step 2: End

Flowchart

This is the flowchart to check whether number is less than 50 or not

Flowchart : An effective way to use of Else If

Now, Let’s look an code to understand how to check whether number is less than 50 or not with the use of else if

CODE: Use of Else if

#include<stdio.h>

int main()
{
    
    int number;
    printf("Please enter a number: ");
    scanf("%d",&number);
    
    //For single statements we can skip the curly brackets
    if(number < 50)
        printf("\nNumber is less than 50!\n");
    else
        printf("\nNumber is greater than 50!\n");
    
    return 0;
}                   

Download Application: Learn C Programming with Live Compiler

The output of above program is

Please enter a number: 12
Number is less than 50!

Please enter a number: 57
Number is greater than 50!
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Join Our Newsletter Now

Get the latest tutorials, examples and projects updates.

Ads Block Detector Powered by codehelppro.com

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Disable Ad Block

Want Same System