Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #define N 10
- static double *input(void){
- char buf[BUFSIZ];
- double *dat = (double *) malloc(N * sizeof(double));
- int i = 0;
- double d;
- while (i < N) {
- printf("Input %d: ", i + 1);
- fgets(buf, BUFSIZ, stdin);
- d = atof(buf);
- if (d <= 0) continue;
- dat[i++] = d;
- }
- return dat;
- }
- static double com1(double *dat) {
- double sum = 0., average, diff = 0.;
- int i;
- for (i = 0; i < N; i++) sum += dat[i];
- average = sum / N;
- for (i = 0; i < N; i++) diff += (dat[i] - average) * (dat[i] - average);
- return sqrt(diff / N);
- }
- static double com2(double *dat) {
- double min = dat[0];
- int i;
- for (i = 1; i < N; i++) if (min > dat[i]) min = dat[i];
- return min;
- }
- int main(void) {
- double *dat = input();
- printf("Standard Diviation: %lf\n", com1(dat));
- printf("Minimum: %lf\n", com2(dat));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement