SHARE
TWEET

TASK3/2

Mary_99 Jan 31st, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <math.h>
  3. void statistica(float numbers[], int size, float results[]){
  4.     float min=numbers[0];
  5.     float max=numbers[0];
  6.     float variable=0;
  7.     float sum=0;
  8.     int i;
  9.     for(i=0; i<size; i++){
  10.         if(numbers[i]<min)
  11.             min = numbers[i];
  12.         else if(numbers[i]>max)
  13.             max = numbers[i];
  14.         sum = sum+numbers[i];
  15.     }
  16.     sum = sum/size;
  17.     for(i=0; i<size; i++){
  18.         variable = variable + pow((numbers[i]-sum), 2);
  19.     }
  20.     variable = variable / (size-1);
  21.     results[0] = min;
  22.     results[1] = max;
  23.     results[2] = variable;
  24. }
  25.  
  26. int main() {
  27.     int amount;
  28.     int i;
  29.     printf("How many numbers do you want to input? ");
  30.     scanf("%d", &amount);
  31.     float numbers[amount];
  32.     float results[3];
  33.     for(i=0; i<amount; i++){
  34.         printf("insert a number: ");
  35.         scanf("%f", &numbers[i]);
  36.     }
  37.     statistica(numbers, amount, results);
  38.     printf("min: %f, max: %f, variance: %f ", results[0], results[1], results[2]);
  39.     return 0;
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top