Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment 3: Arrays An Average Problem Due Monday, July 25, 2011 by 11:59:59 pm

ID: 3627583 • Letter: A

Question

Assignment 3: Arrays
An Average Problem

Due Monday, July 25, 2011 by 11:59:59 pm PST
Write a program that reads one or more sets of numbers from the user. Each set of numbers consists of an integer N followed by N integer values. These values will be in the range from -1,000,000 to 1,000,000 (guaranteed). Your task is to compute the mean, median, and mode of each set of N integers. N may range from 1 to 25.

As output for each set of numbers, print a single line containing the word "Mean" followed by the mean, the word "Median" followed by the median, and the word "Mode" followed by the mode, leaving enough spacing on the line to allow easy readability. Subsequent lines should be aligned with the first line (thus creating columns). Fractional portions should be correct to at least two decimal positions.

Definitions for purposes of this problem:
Mean is defined as the result of dividing the sum of the N numbers by N, the number of numbers.
Median is the "middle" number. That is, in an ordered list of numbers, the one in the middle of the list is the median. If N is even, then the mean of the two numbers in the middle is the median.
Mode is the value that occurs most often in the list. In case of ties, report the smallest value that meets the criteria.
Sample input:
How many numbers 5

Please enter 5 numbers


1
3
5
4
5


Mean: 3.60 Median: 4 Mode: 5


Go again (y/n) y


How many numbers 4


Please enter 4 numbers


6
2
5
25


Mean: 9.50 Median: 5.50 Mode: 2

Go again (y/n)




--------------------------------------------------------------------------------


Development Details
Design your code in as modular a fashion as possible. Individual tasks should go in individual functions. You WILL be graded heavily on this.
No set of numbers will be bigger than 25. This means you will declare a static array of 25. You will fill that array with as many numbers as specified within the file. You will have to ensure you don’t use more of the array than required.
Error checking for range is a must

Name the C file that contains your main method cscd255hw3.c

What I have so far is

/*The Average Problem*/
//by Nicole Hicks
#include <stdio.h>
#include <stdlib.h>
#define MAX 25
int readTotal();
int goAgain();
void printArray(double mean,double median,double mode);
void fillArray(int numbers[], int total);
double findMode(int numbers[],int total);
double findMedian(int numbers[],int total);
double findMean(int numbers[], int total);
void sort(int numbers[], int total);
//main method
int main(int argc, char *argv[])
{
int total;
double mean,median,mode;
int array[MAX];
int i;

do
{
//function call to read n value
sort(array,total);
total=readTotal();
fillArray(array,total);
mean=findMean(array,total);
median=findMedian(array,total);
mode=findMode(array,total);
printArray(mean,median,mode);

}while(goAgain());


system("pause");
}
//prints output
void printArray(double mean,double median,double mode)
{
printf("Mean; %.2lf median; %.2lf mode; %.0lf ", mean, median, mode);
}
int goAgain()
{
char ch;
while(getchar()!=' ')
;
while(ch!= 'y' && ch != 'Y'&&ch!='n'&& ch!='N')
{
printf("go again? (y/n)");
scanf("%c", &ch);
while(getchar()!=' ')
;
}
if(ch=='y'||ch=='Y')
return 1;

return 0;
}
//returns mode
double findMode(int numbers[],int total)
{
int temp;
int count=0;
int i;
int j;
int temp2;
int ret;
int count2=0;
for(i=0; i<total;i++)
{
temp=numbers[i];
count=1;
for(j=i+1; j<total; j++)

{
if(temp == numbers[j])
count++;
}


if(count>count2)
{
temp2=temp;
count2=count;
}
}
return temp2;
}
//function returns median
double findMedian(int numbers[],int total)
{
int x;
double median = (double) numbers[total/2];
if(total % 2 == 1)
{
for(x=1; x<total; x++)
{
if(numbers[x]==median)
median=numbers[x];
}
}
else
{
median = (double)(numbers[(total/2)-1] + (numbers[(total/2)]))/2;
}
return median;

}
//function calculates mean of elements
double findMean(int numbers[], int total)
{
int sum=0;
int i;
double mean;
int count=0;
for(i=0;i<total;i++)
{
sum=sum+numbers[i];
}
mean = (sum+0.0)/total;
return mean;
}
void fillArray(int numbers[], int total)
{
int i;
printf("Please enter total numbers");
for(i=0;i<total;i++)
{
printf("%i)", i+1);
scanf("%i", &numbers[i]);
}
}
//function call to read total value
int readTotal()
{
int total=0;
do
{ printf("How many numbers ");
printf(" Please enter numbers between 1 and 25 ");
scanf("%i", &total);

}
while(total<1||total>25)
;
return total;
}
//function call to sort array
void sort(int numbers[], int total)
{
int a[MAX];
int n;
{
int i, j, temp;


for(i=0; j=n-1; i++)
for(j=i+1; j<n; j++)
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}



Explanation / Answer

DEAR FRIEND here is the full program u want in c language any questions just message me PLEASE RATE #include #include //function prototypes declaration int readTotal(); bool goAgain(); void printArray(double mean,double median,double mode); void fillArray(int numbers[], int total); double findMode(int numbers[],int total); double findMedian(int numbers[],int total); double findMean(int numbers[], int total); //main method void main() { double mean,median,mode; int n,array[25]; do { //function call to read n value n=readTotal(); fillArray(array,n); mean=findMean(array,n); median=findMedian(array,n); mode=findMode(array,n); printArray(mean,median,mode); }while(goAgain()); } //prints output void printArray(double mean,double median,double mode) { printf("%s %f %s %f %s %f " ,"Mean: ", mean,"Median: " ,median,"Mode: ", mode); } bool goAgain() { char ch='y'; printf("%s"," Do u want again (y/n)"); ch=getch(); if(ch == 'y' || ch == 'Y') return true; return false; } //returns mode double findMode(int numbers[],int total) { int temp; int arr[25]; int max=1; int ret=0; for(int i=0; i