fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct student{
  5. char name[21];
  6. int height, weight;
  7. };
  8.  
  9. int main(){
  10. int i, n, z, u, sum_height, sum_weight;
  11. double t = 10000.00;
  12. double s = 10000.00;
  13. double Height_avg, Weight_avg;
  14. sum_height = 0;
  15. sum_weight = 0;
  16.  
  17. printf("請輸入人數: ");
  18. scanf("%d", &n);
  19.  
  20. struct student *a = (struct student *)malloc(sizeof(struct student)*n);
  21.  
  22. for (i = 0; i < n; i++){
  23. scanf("請輸入姓名 身高 體重: %s %d %d", &a[i].name, &a[i].height, &a[i].weight);
  24. }
  25.  
  26. for (i = 0; i < n; i++){
  27. sum_height += a[i].height;
  28. sum_weight += a[i].weight;
  29. }
  30.  
  31. Height_avg = sum_height / n;
  32. Weight_avg = sum_weight / n;
  33.  
  34. printf("Height_avg: %lf", Height_avg);
  35. printf("Weight_avg: %lf", Weight_avg);
  36.  
  37. for (i = 0; i < n; i++){
  38. if(a[i].height < t){
  39. t = a[i].height;
  40. z = i;
  41. }
  42. if(a[i].weight < s){
  43. s = a[i].weight;
  44. u = i;
  45. }
  46. }
  47.  
  48. if (a[i].height < Height_avg || a[i].weight < Weight_avg){
  49. printf("%s", a[z].name);
  50. printf("%s", a[u].name);
  51. }
  52.  
  53. free(a);
  54. system("pause");
  55. return 0;
  56. }
  57.  
Runtime error #stdin #stdout 0.01s 2748KB
stdin
Standard input is empty
stdout
Standard output is empty