Calculating the Median

This is a discussion on Calculating the Median within the C Programming forums, part of the General Programming Boards category; Hi im now trying to work on calculating the mean, were by the array is arranged into size order, and ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    12

    Calculating the Median

    Hi

    im now trying to work on calculating the mean, were by the array is arranged into size order, and the the median is printed out, i am having problems with the code, the cmd.exe flashes open then shut again, i am not recieving any errors, any ideas. im using visual studio C++ 2010

    Code:
    #include <stdio.h>
    #define Size 11
    int main()
    {
    float median[]={13, 36, 16, 21, 24, 16, 21, 10, 18, 16};
    int x;
    int y;
    float temp;
    int stop;
    
    
    for(x=0; x<Size; x++)
    	{
    		for(y=x+1; y<Size; y++)
    		{
    			if(median[y]>median[x])
    			{
    				temp=median[x];
    				median[x] = median[y];
    				median[y] = temp;
    			}
    		}
    	}
    
    
    	if(Size%2==0)
    	return printf("%f\n",(median[Size/2]+median[Size/2-1])/2);
    	else
    	return printf("%f\n",median[Size/2]);		
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,396
    Quote Originally Posted by openwindow
    the cmd.exe flashes open then shut again, i am not recieving any errors, any ideas. im using visual studio C++ 2010
    By default, Visual Studio C++ 2010 should pause the console window for you. Besides changing whatever setting is required, read: Pause console.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Median Help!
    By tidbit in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2010, 09:55 PM
  2. Median filter help
    By JTEK24 in forum Tech Board
    Replies: 10
    Last Post: 07-16-2009, 06:05 PM
  3. Median
    By Neo1 in forum C++ Programming
    Replies: 4
    Last Post: 07-02-2007, 04:00 PM
  4. Median
    By Suchy in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2006, 02:07 AM
  5. median
    By frank in forum C++ Programming
    Replies: 4
    Last Post: 10-28-2001, 03:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21