Finding a Middle number out of three numbers

Problem Statement
  Write a program to read three integers A, B and C in a read_data function.
   The main  program must find the middle element. Another function print_data
   must print the middle      element. You need to call the read_data function
   three times to read three variables.

   function prototypes
   **********************************
   int read_data();
   void print_data(int value);
#include<stdio.h>
int read_data();
void print_data(int value);
int main()
{
  int a[3],i;
  printf("enter the numbers \n");
  for(i=0;i<3;i++)
    {
      a[i]=read_data();
    }  
  if(a[0]>a[1])
    {
      if(a[2]>a[0])
{
 print_data(a[0]);
}
      else if(a[2]>a[1])
{
 print_data(a[2]);
}
      else
{
 print_data(a[1]);
}
    }
  else
    {
      if(a[2]>a[1])
        {
 print_data(a[1]);
        }
      else if(a[2]>a[0])
        {
 print_data(a[2]);
}
        else
 {
            print_data(a[0]);
 }
    }
  return 0;
}
int read_data()
{
  int temp;
  scanf("%d",&temp);
  return temp;
}
void print_data(int data)
{
  printf("the middle number is %d \n",data);
  return ;
}    

No comments:

Post a Comment