C program- find the lowest student score above, and the highest score below the boundary -
i finishing program read in bunch of non-negative doubles array, calculate mean , stand dev of values. mean plus stand dev represents getting b.
having trouble next part, need find lowest score array of numbers give me b, , highest value in array did not b. having trouble part amazing.
have make program stop when eof
typed it, can not figure part out either, appreciated. instead made work positive values , stop when negative value introduced, here code:
#include <stdio.h> #include <math.h> int main () { int arr[100]; int y, x; int i; double mean = 0; double std = 0; double = 0; = 0; printf("enter next number, eof stop > ") ; scanf("%d",&x); while (x >= 0) { arr[i++] = x; printf ("enter next number, eof stop > " ); scanf("%d",&x); } y = i; double sum = 0; double sum1= 0; for(i = 0; < y; i++){ sum = sum + arr[i]; } mean = sum / y; (i = 0; < y; i++){ sum1 = sum1 + pow((arr[i] - mean), 2); } std = sum1 / ((float)y - 1); = mean + sqrt(std); if (10 > y) { printf("**you must enter atleast 10 scores***\n"); return 0; } printf("mean = %.2lf, standard deviation = %.2lf\n", mean, sqrt(std)); printf("scores above %.2lf b\n", this); return 0; }
code:
#include <stdio.h> #include <math.h> int main () { int arr[100]; int y, x; int i; double mean = 0; double std = 0; double margin = 0; = 0; printf("enter next number, eof stop > ") ; scanf("%d",&x); while (x >= 0) { arr[i++] = x; printf ("enter next number, eof stop > " ); scanf("%d",&x); } y = i; if (10 > y) { printf("**you must enter atleast 10 scores***\n"); return 0; } double sum = 0; double sum1= 0; for(i = 0; < y; i++){ sum = sum + arr[i]; } mean = sum / y; (i = 0; < y; i++){ sum1 = sum1 + pow((arr[i] - mean), 2); } std = sum1 / ((float)y - 1.0); margin = mean + sqrt(std); printf("mean = %.2lf, standard deviation = %.2lf\n", mean, sqrt(std)); printf("scores above %.2lf b\n", margin); int below = arr[0]; // highest value in array not b int above = arr[0]; // lowest value in array give b (i=0; i<y; i++) { if ((arr[i] > below) && (arr[i] < margin)) { below = arr[i]; } else if ((arr[i] > margin) && (arr[i] < above)) { above = arr[i]; } } return 0; }
Comments
Post a Comment