once again teaching myself to write using C, damn I miss C++

the question is to write a program that can calculate the first, second, and third quartiles for a set of data. I need to declare 2 arrays, each having 3 columns. The quartiles will be calculated for only one of the three columns of each array. The user chooses which column of each array to process.

to start off I wanted to use 4 functions;
1 to check input
1 to perform bubble sort
1 to calculate the quartiles
1 for main


this is all i have so far

do
    {
        still_changing = 0;

        for(i = 0; i < 3; i++)
            if(data[i+1] < data[i])
            {
                temp = data[i];
                data[i] = data[i+1];
                data[i+1] = temp;
                still_changing = 1;
                printArray(data);
            }

    } while (still_changing);
}

In descriptive statistics, a quartile is any of the three values which divide the sorted data set into four equal parts, so that each part represents one fourth of the sampled population.

With that definition, all you have to do is sort the array, then use the array element that represents 0-25%, 26-50%, 51-75%, and 76-100% of the elements

The way I understand this, say you have an array of 16 sorted numbers. The quartiles will be the values at array element numbers 4, 8, and 12

what? I'm lost...

array1 has the following
8362 27114 2760
10176 12747 4545
21711 2887 12200
22296 8004 22202
24085 26045 16587
14338 24039 7045
7925 16697 28772
3567 11610 15209
3832 4868 25320
5783 11050 20865
6522 6912 10957
7224 2988 16290
29819 7348 25838
18942 8255 4380
6104 6941 8338
8537 28350 19921
30601 3963 2691
2621 19532 18265
17330 12951 29898
4472 8650 19757

array 2 has the following
8610 24792 16949
3980 10223 8064
28881 9790 21897
13794 29531 25550
2704 5614 32023
21313 30591 31106
15988 2332 11615
470 5857 24031
32314 26135 6369
12751 16851 30034
5218 7672 21140
28564 6987 13939

this is basically what I'm suppose to do

1. There are many types of descriptive statistics that can be reported for a set of data. One is the quartile, in which the data is broken up into four parts, each with an equal number of samples. The first, second, and third quartiles represent the values below which 25%, 50%, and 75% of the sample values lie, respectively. For example, when I report the grades of the class I include the second quartile, more commonly known as the median.
2. Write a program that can calculate the first, second, and third quartiles for a set of
data. 3. Your program will declare two arrays, each of which has three columns. The particular values can be found on the course website. 4. The quartiles will be calculated for only one of the three columns of each array. The user chooses which column of each array to process.
5. main() will have this form:
main()
prompt user for column to process in array 1 check validity of response pass array 1, column #, and number of rows to function prompt user for column to process in array 2 check validity of response
pass array 2, column #, and number of rows to function

Additional requirements:
1. Perform some basic error checking on the response provided by the user.
2. You will write a function that will be passed an array, the number of the column to process, and the number of rows in the array. The declaration will look like this:
void stats(int data[][3], int col, int rows);

first sort the array by the desired column

Because there are 20 rows, the 1st quartile will consist of rows 0-4 (5 rows), the 2nd quartile is rows 5-9, 3d is rows 10-14, and the 4th is rows 15-19.

The problem I see with your assignment is: "what are you supposed to do with that information?" Do you just print (display) the values in each quartile, create 4 arrays and copy the values into them? Or something else?

this is my finished code.

can someone tell me if I did an ok job?

#include <stdio.h>

void stats (int Array[][3], int x, int y);

int main (void)
{

int Array1 [][3] = {{8362, 27114, 2760},
                    {10176, 12747, 4545},
                    {21711, 2887, 12200},
                    {22296, 8004, 22202},
                    {24085, 26045, 16587},
                    {14338, 24039, 7045},
                    {7925, 16697, 28772},
                    {3567, 11610, 15209},
                    {3832, 4868, 25320},
                    {5783, 11050, 20865},
                    {6522, 6912, 10957},
                    {7224, 2988, 16290},
                    {29819, 7348, 25838},
                    {18942, 8255, 4380},
                    {6104, 6941, 8338},
                    {8537, 28350, 19921},
                    {30601, 3963, 2691},
                    {2621, 19532, 18265},
                    {17330, 12951, 29898},
                    {4472, 8650, 19757}};
                        
int Array2 [][3] = {{8610, 24792, 16949},
                    {3980, 10223, 8064},
                    {28881, 9790, 21897},
                    {13794, 29531, 25550},
                    {2704, 5614, 32023},
                    {21313, 30591, 31106},
                    {15988, 2332, 11615},
                    {470, 5857, 24031},
                    {32314, 26135, 6369},
                    {12751, 16851, 30034},
                    {5218, 7672, 21140},
                    {28564, 6987, 13939}};

	int col1, col2;
    printf("What column do you want to procress in Array1?  ");
    scanf("%d", &col1);
	if(col1<1||col1>3)
		return 1;

    printf("What column do you want to process in Array2?  ");
    scanf("%d",  &col2);
	if(col2<1||col2>3)
		return 1;


	int row1 = 20;
	int row2 = 12;    

    stats(Array1, row1, col1);
	stats(Array2, row2, col2);
	
}


void stats(int Array[][3], int x, int y)
{
	int still_changing, i, temp;
	y--;
do
{
          still_changing = 0;
          
          for(i = 0; i < x-1; i++)
            if(Array[i + 1][y] < Array[i][y])
            {
                       temp = Array[i][y];
                       Array[i][y] = Array[i + 1][y];
                       Array[i + 1][y]= temp;
                       still_changing = 1;
                       
            }
    } while (still_changing);


	for(i = 0; i<x;i++)
		printf("%d\n",Array[i][y]);
    
    printf("\n");
	printf("The first quadrant is %d\n",Array[x*1/4][y]);
	printf("The second quadrant is %d\n",Array[x*1/2][y]);
	printf("The third quardant is %d\n",Array[x*3/4][y]);
	
	
}
This article has been dead for over six months. Start a new discussion instead.