Find elements

C program to find middle among three number using function

C program to find middle among three number using function

In this tutorial, we will discuss the concept of C program to find middle among three numbers using function

This post describes how to find the middle number among three numbers using if statements in C language

There are many ways to find the middle number of the three numbers. but here, we mainly focus on using  if-else-if statements in C.

find middle of three number

 

Using Nested if statements  to find the middle

#include <stdio.h>
#include <stdlib.h>
int middleNumber(int,int,int);//function prototype
int main()
{
    int num1,num2,num3;
    printf("Enter the three numbers\n");
    scanf("%d %d %d",&num1,&num2,&num3);//takes input from user
    printf("Middle number is %d",middleNumber(num1,num2,num3));//function call
    getch();
    return 0;
}

int middleNumber(int num1,int num2,int num3){//function definition
    int middle=0;

    if(num1>num2){
        if(num2>num3){
        middle=num2;
    }
    else if(num3>num1){
        middle=num1;
    }
    else{
        middle=num3;
    }
    }

    else{

        if(num2<num3){
        middle=num2;
    }
    else if(num3<num1){
        middle=num1;
    }
    else{
        middle=num3;
    }

}

}

When the above code is executed, it produces the following results

Enter the three numbers
23
45
78
Middle number is 45

Similar post

Java program to find the middle of three number using Method

Python program to find the middle of three number using the function

 

 

Suggested for you

Operator in C language

If statement in C language

Data type in C language

Variable in C language

 

C++ program to find middle of three number using function
Python program to find middle of three number using function
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago