Advertisement
cyter

Maximum Cost Exchange

Sep 8th, 2016
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. //Please review my code
  2. #include <stdio.h>
  3. #include <math.h>
  4. main()
  5. {
  6.     int students, i = 0;
  7.     float average, total = 0.0, sum = 0.0, num;
  8.     float *costs;
  9.     prinf("Enter the number of students: ");
  10.     scanf("%d\n",students);
  11.     while(students != 0){      
  12.         costs = malloc(students*sizeof(double));
  13.         while(i < students){
  14.             scanf("%f",&num);
  15.             sum += num;
  16.             costs[i++] = num;
  17.         } average = sum/students;
  18.         for(i = 0; i < students; i++){
  19.             total += floor((costs[i] - average)*100)/100;
  20.         } printf("%f",total);
  21.         i = 0;
  22.         sum = 0.0;
  23.         total = 0.0;
  24.         free(costs);
  25.         prinf("Enter the number of students: ");
  26.         scanf("%d\n",students);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement