I'm trying to create a function to calculate the mode of 11 items entered into an array. Can anyone help me with this? Thanks!
I'm trying to create a function to calculate the mode of 11 items entered into an array. Can anyone help me with this? Thanks!
I'll correct your code for you...
-Govtcheez
[email protected]
You need to give us more information about what you want to do
Sorry, I'm new here...
I have to write a program that inputs 11 floating point values from the keyboard, then print our the numbers in ascending order along with the mean, median and mode of the array. I figured out everything but the mode. I attached my code.
> Sorry, I'm new here...
No prob - everyone was new at one point.
but....
> I attached my code.
No, you didn't....
-Govtcheez
[email protected]
Well, I tried to attach it...here, I'll include it instead:
# include <stdio.h>
# define INPUT 11
// --- Prototypes ---
void getData(float A[]);
void bubblesort(float A[]);
void printOutput(float A[]);
void mean(float A[]);
void median(float A[]);
void main(void)
{
int stop;
float A[INPUT];
getData(A);
bubblesort(A);
printOutput(A);
mean(A);
median(A);
scanf("%i", &stop);
}
// Function: getData
// Precondition: None
// Postcondition: Fills array with numbers input by user
void getData(float A[])
{
int count;
for (count = 0; count < INPUT; count++)
{
printf("Enter number %2i: ", count + 1);
scanf("%f", &A[count]);
}
}
// Function: bubblesort
// Precondition: Floating point array
// Postcondition: Array is sorted in ascending order
void bubblesort(float A[])
{
int i, j, didswap;
float temp;
for (i = 0; i < INPUT; i++)
{
didswap = 0;
for (j = 0; j < INPUT - i; j++)
if (A[j] > A[j + 1])
{
temp = A[j];
A[j] = A[j + 1];
A[j + 1] = temp;
didswap = 1;
}
if (didswap == 0)
break;
}
}
// Function: printOutput
// Precondition: Sorted floating point array
// Postcondition: Prints elements of sorted array
void printOutput(float A[])
{
int i;
printf("\nSorted array follows:\n");
for (i = 0; i < INPUT; i++)
{
printf("%.2f ", A[i]);
}
printf("\n\n");
}
// Function: mean
// Precondition: Sorted floating point array
// Postcondition: Prints mean of sorted array
void mean(float A[])
{
int count;
float sum = 0;
for (count = 1; count <= INPUT; ++count)
{ sum += A[count - 1];
}
printf("Array Mean : %.2f", sum /= INPUT);
}
// Function: median
// Precondition: Sorted floating point array
// Postcondition: Prints median of sorted array
void median(float A[])
{
printf("\nArray Median : %.2f\n", A[5]);
}