Can anyone give me some ideas on how to find the middle value between 3 numbers.? I really dont know how to start...

I know how find minimum and maximum but finding the Middle value is kinda hard for me...

For those C Wizards give me some idea advice please?., just an idea u dont have to give codes... thx!

Can anyone give me some ideas on how to find the middle value between 3 numbers.? I really dont know how to start...

I know how find minimum and maximum but finding the Middle value is kinda hard for me...

For those C Wizards give me some idea advice please?., just an idea u dont have to give codes... thx!

What exactly do you mean by middle value?
U can do it by using (a+b+c)/3
I hope its not that simple. Kindly explain what you mean by middle value

Do you mean something like this?:

#include <stdio.h>
#include <string.h>

int main(int argc, char** argv)
{
	char strData[128] = {'\0'};
	int intMiddle = 0;
	
	do
	{
		puts("Please enter some data");
		gets(strData);
	} while(NULL == strData[0]);
	
	
	intMiddle = (int)(strlen(strData)/2);
	
	printf("The middle is [%c]\n", strData[intMiddle]);
}

Can anyone give me some ideas on how to find the middle value between 3 numbers.?

Assuming it is always 3 numbers, and what you want is the median value, here is a simple way. Find the maximum then the minimum and the one you didn't pick is the median. :)

Also, if the numbers aren't too far apart, then what you could do
is get the average of the 3 numbers, and find the number that is closest
to the average. This will work long as the number aren't too far apart, like
1,2,100;

for example if the input was 1,2,3 and you know that the median is 2,
but if you found the average, totalSum/totalElement = (3+2+1)/3 = 6/3 = 2, then you see that this also gets the correct answer. Use it at your
own risk.

#include <stdio.h>

int main()
{
    int a,b,c;
    int min,mid,max,i=1;
    
    printf("Enter number: ");
    scanf("%d",&a);
    printf("\nEnter number: ");
    scanf("%d",&b);
    printf("\nEnter number: ");
    scanf("%d",&c);
    
   if(((a<b)&&(b<c)) || ((a>b)&&(a<c)))
    {
        min=a;
        mid=b;
        max=c;
    }
    if(((b<a)&&(a>c)) || ((a>b)&&(a<c)))
    {
        min=c;
        mid=a;
        max=b;
    }
    if(((c<a)&&(c>b)) || ((c>a)&&(c<b)))
    {
        min=b;
        mid=c;
        max=a;
    }

    printf("\nMin is %d",min);
    printf("\nMid is %d",mid);
    printf("\nMax is %d",max);   
    
    printf("\n");
    
    
    for(i=min;i<=max;i++)
    {
                  
                  
                  if(i==mid)
                  continue;
                  printf("\n%d",i);
    }
    
    getchar();
    getchar();
    
}

Here's it is...I can find the min, mid and max...
But the problem is when i enter a Descending values like... a=3,b=2,c=1...
i got wrong output... try it,.,.

i dont know why? do i have a wrong if statement?

To find out the media, use an array and a bubble sort to get them in order, then keep going until you are at the middle element.

I hope what he wants he is just " find the middle element when you have given three elements"

Ex: 1,3,6 the middle element is 3 ( this we cant get just by dividing)
5,6,7 the the middle element is 6.

if this is the case :

int find_mid(int n1, int n2, int n3)
{
  int mid;
  if( n1 > n2 )   {
          if( n3 > n2)
                {
                        if( n3 < n1 )
                                mid = n3;
                        else
                                mid = n1;
                }
         else {
                mid = n2;
        }
 }
 else {
        if( n2 > n3 )
         {
                if ( n1 > n3)
                  mid = n1;
                else
                mid = n3;
         }
        else{
                mid = n2;
        }
}
return mid ;
}

the driver:

int main()
{
        printf( "%d  ", find_mid(3,4,7) );
        printf( "%d  ", find_mid(5,2,8) );
        printf( "%d  ", find_mid(2,9,4) );
        printf( "%d  ", find_mid(7,5,9) );
        printf( "%d  ", find_mid(7,4,6) );
        printf( "%d  ", find_mid(1,3,6) );
        printf( "%d  ", find_mid(5,6,7) );
return 0;
}

Thank you so much...

lam3r...

I really appreciate your help...

hello frnds pls send me logic of fibo nacci series...........
my mai address is krutarthdoshi 14@gmail.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.