1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
// Proj 5.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
int findVar(int, int, int);
int _tmain(int argc, _TCHAR* argv[])
{ int n;
printf ("Please enter an integer: ");
scanf("%d", &n);
while((n < 50) && (n > 0)){
srand(n);
if (n > 5)
n=5;
int i=0, v[50], sum = 0;
float average;
while (i < n){
int x=rand() % 6;
printf("%d: i=%d, n=%d\n", x, i, n);
v[i]=x;
sum = sum + x;
i++;
}
average = (float) sum / n;
// We have found the average, now we need to find median, and mode.
printf ("v0= %d, v1 = %d, v2 = %d, v3 = %d, v4 = %d\nMean: %.2f\n\n", v[0], v[1],v[2], v[3], v[4], average);
scanf("%d", &n);
}
return 0;
}
| |