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…

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

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
if(no1<no2)
tmid1= no1;
else
tmid1=no2;
//2nd If :Use to define the minimum of 2nd and 3rd numbers
if(no2<no3)
tmid2=no2;
else
tmid2=no3;

//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
if(no1<no3)
mid=no1;
else
mid=no3;
}
else
//This is the False part. If no2 isn’t the min value,we take max of the temporary middles as the middle value
if(tmid1>tmid2)
mid=tmid1;
else
mid=tmid2;

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 KDJGuru
/// WISH YOU ALL THE BEST
/// #Stay_Home #Flatten_the_Curve

}

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

BMaxx
Author

Write A Comment