The median of five input numbers!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • suhdominic
    New Member
    • Feb 2007
    • 6

    The median of five input numbers!!!

    Can anyone help me how to program in C++ which determines the median of five input numbers?
  • praveenholal
    New Member
    • Feb 2007
    • 19

    #2
    Originally posted by suhdominic
    Can anyone help me how to program in C++ which determines the median of five input numbers?
    Give me the formula and other necesary inputs.I will try to help you

    Comment

    • suhdominic
      New Member
      • Feb 2007
      • 6

      #3
      Originally posted by suhdominic
      Can anyone help me how to program in C++ which determines the median of five input numbers?
      the median is the middle number when the five numbers are arranged in order. the user can input the values in any order. so your program must determine which value is the other four for example, if the user enters

      41.52 27 96.01 12.1 103.55

      then the program should output

      the median of 41.52 27 96.01 12.1 and 103.55 is 41.52

      Comment

      • suhdominic
        New Member
        • Feb 2007
        • 6

        #4
        The median of five input numbers!!!

        Determining the median of five input numbers in C++
        --------------------------------------------------------------------------------

        Can anyone help me how to program in C++ which determines the median of five input numbers?

        the median is the middle number when the five numbers are arranged in order. the user can input the values in any order. so your program must determine which value is the other four for example, if the user enters

        41.52 27 96.01 12.1 103.55

        then the program should output

        the median of 41.52 27 96.01 12.1 and 103.55 is 41.52

        i don't know where to start with im assuming to use if function

        Comment

        • praveenholal
          New Member
          • Feb 2007
          • 19

          #5
          Originally posted by suhdominic
          the median is the middle number when the five numbers are arranged in order. the user can input the values in any order. so your program must determine which value is the other four for example, if the user enters

          41.52 27 96.01 12.1 103.55

          then the program should output

          the median of 41.52 27 96.01 12.1 and 103.55 is 41.52





          hi i am giving a easy method for calculating , see that whether you can implement it



          Example 1: To find the median of 4,5,7,2,1 [ODD].
          Step 1: Count the total numbers given.
          There are 5 elements or numbers in the distribution.

          Step 2: Arrange the numbers in ascending order.
          1,2,4,5,7

          Step 3: The total elements in the distribution (5) is odd.
          The middle position can be calculated using the formula. (n+1)/2
          So the middle position is (5+1)/2 = 6/2 = 3
          The number at 3rd position is = Median = 4

          ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
          just i am summarising the steps you need to implement
          1)Declare a array of 5 elements
          2)Sort the contents of the array in ascending order
          3)Calculate middle position using formula (n+1)/2
          4)store (n+1)/2 in result.
          5) array[result] is your required Answer

          Implement this in c++.

          Comment

          • praveenholal
            New Member
            • Feb 2007
            • 19

            #6
            hi i am giving a easy method for calculating , see that whether you can implement it



            Example 1: To find the median of 4,5,7,2,1 [ODD].
            Step 1: Count the total numbers given.
            There are 5 elements or numbers in the distribution.

            Step 2: Arrange the numbers in ascending order.
            1,2,4,5,7

            Step 3: The total elements in the distribution (5) is odd.
            The middle position can be calculated using the formula. (n+1)/2
            So the middle position is (5+1)/2 = 6/2 = 3
            The number at 3rd position is = Median = 4

            ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
            just i am summarising the steps you need to implement
            1)Declare a array of 5 elements
            2)Sort the contents of the array in ascending order
            3)Calculate middle position using formula (n+1)/2
            4)store (n+1)/2 in result.
            5) array[result] is your required Answer

            Implement this in c++.

            Comment

            • praveenholal
              New Member
              • Feb 2007
              • 19

              #7
              Try it out . I have the solution ready , i.e Program is up and giving results. I want you to try and program it. if u find any dificulties i am there to help you out.

              Comment

              • suhdominic
                New Member
                • Feb 2007
                • 6

                #8
                Thank you for a great help but my course haven't went to array thing yet so is there any other way just using if to figure out the median?thank you

                Comment

                • suhdominic
                  New Member
                  • Feb 2007
                  • 6

                  #9
                  #include <iostream>

                  using namespace std;

                  int main()
                  {
                  float a,b,c,d,e;
                  float Median;
                  int i;

                  cout << "Pleaes enter five float numbers separated by space: " << endl;
                  cin >> a >> b >> c >> d >> e;

                  i = a + b + c + d + e;

                  if (i % 2 == 0)
                  {
                  Median = i/5;
                  cout << "The median of " << a << ", " << b << ", " << c << ", " << d << " and " << e << " is " << Median << endl;
                  }
                  else
                  {

                  this is what i worked so far but it gives the answer when the sum of the values are even but i don't know how to do odd one without using array i don't know what that is and i don't think i supposed to use that

                  Comment

                  • sicarie
                    Recognized Expert Specialist
                    • Nov 2006
                    • 4677

                    #10
                    I have merged these threads as the questions and OPs are the same.

                    Comment

                    • praveenholal
                      New Member
                      • Feb 2007
                      • 19

                      #11
                      Originally posted by suhdominic
                      #include <iostream>

                      using namespace std;

                      int main()
                      {
                      float a,b,c,d,e;
                      float Median;
                      int i;

                      cout << "Pleaes enter five float numbers separated by space: " << endl;
                      cin >> a >> b >> c >> d >> e;

                      i = a + b + c + d + e;

                      if (i % 2 == 0)
                      {
                      Median = i/5;
                      cout << "The median of " << a << ", " << b << ", " << c << ", " << d << " and " << e << " is " << Median << endl;
                      }
                      else
                      {

                      this is what i worked so far but it gives the answer when the sum of the values are even but i don't know how to do odd one without using array i don't know what that is and i don't think i supposed to use that






                      Follow the logic mentioned below and u can solve ur problem.


                      Example 1: To find the median of 4,5,7,2,1 [ODD].
                      Step 1: Count the total numbers given.
                      There are 5 elements or numbers in the distribution.

                      Step 2: Arrange the numbers in ascending order.
                      1,2,4,5,7

                      Step 3: The total elements in the distribution (5) is odd.
                      The middle position can be calculated using the formula. (n+1)/2
                      So the middle position is (5+1)/2 = 6/2 = 3
                      The number at 3rd position is = Median = 4

                      Comment

                      Working...