fork download
  1. #include <stdio.h>
  2.  
  3. void compute_mass(int num,float *mass,float *sum,float *ave) {
  4. int i=0;
  5. *sum = 0;
  6. *ave = 0;
  7. for(i=0;i<num;i++) {
  8. *sum = *sum + mass[i];
  9. }
  10. if(num) {
  11. *ave = *sum/((float) num);
  12. }
  13. }
  14.  
  15. int main(void) {
  16. // your code goes here
  17. int i;
  18. float taiju[10]={58.6,65.2,74.4,46.0,52.8,62.4,55.0,51.2,54.8,48.4};
  19. float total,average;
  20. compute_mass(10,taiju,&total,&average);
  21.  
  22. printf("Total=%.1f\n",total);
  23. printf("Average=%.1f\n",average);
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
Total=568.8
Average=56.9