Middle value of three numbers in C language

Hello Guys. Welcome you all to my new article on Tips and Tricks. Today I’m going to show how we can find the middle value of three numbers in C language.

If you have search this question in google, surely you have found lot of methods that very hard to understand. But in here I’m giving you a very simple and basic method to find it. There are no logical expressions as “AND” , “NOT” and “OR”. But I’m using only the IF condition.

Flow of the method..

  • Input three numbers. Let suppose them as No1, No2,and No3
  • Then pair them as {No1 , No2 } and { No2 , No3}
  • Now you have to get the min value of each pair.  Suppose them as Min1 and Min2.
  • Compare that both Min1 and Min2 are the same.
    • IF yes ; Get the min value of No1 and No3. It is the middle Value.
    • IF no : Get the max value of Min1 and Min2. It is the middle value.

Wire Diagram…

middle num


This is the way of find the Middle Value of three numbers in C language. This is the code for the program. You can simply copy and paste it.

Source Code

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

int main()

{ int no1,no2,no3;
int tmid1,tmid2,mid;
//tmid1 and tmid2 represent the temporary middles

// tmid1 and tmid2 represent the min1 and min2 according to above diagram

printf("Input Three Counting Nubers : ");
scanf("%d %d %d",&no1,&no2,&no3);

///Logical Part
//1st If :Use to define the minimum of 1st and 2nd numbers
tmid1= no1;
//2nd If :Use to define the minimum of 2nd and 3rd numbers

//3rd If : Use to define that "is the tmid1 and tmid2 are same?" If they are same it explicit that no2 is the minimum

if (tmid2==tmid1)
{ //This is the TRUE part. If no2 is the min value,we take min of the no1 & no2 as the middle value
//This is the False part. If no2 isn't the min value,we take max of the temporary middles as the middle value

printf("Middle is %d \n \n ",mid);
return 0;

/// I hope you learned something and enjoyed the program.
///A program by Bonomi Tharinda(BMaxx) at Digital Chalkie
/// #Stay_Home #Flatten_the_Curve

retur thye esh

You can simply copy this code and paste it on your codeblocks.  So guys this is time to wind up. Wish you all the Best. Bye Bye. See you soon. Please stay in your homes and help to flatten the curve during this corona virus pandemic

Bonomi Tharinda
Bonomi Tharinda is the Developer of the BMaxx Blog. He is a skilled web developer and graphic designer. In addition, he is an undergraduate student of a representative University in Sri Lanka. He is working as a tutor of an institute and as a part-time blogger, he will help you all to make your problems solved.Here are his social accounts and you can follow him through them.