fork download
  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4. struct Body{
  5. int id;
  6. double height;
  7. double weight;
  8. double bmi;
  9. };
  10.  
  11. int main(void)
  12. {
  13. struct Body data[] = { { 1, 170, 60 },
  14. { 2, 150, 50 },
  15. { 3, 160, 56 },
  16. { 4, 180, 70 } };
  17.  
  18. for(int i=0; i<4; i++){
  19. data[i].bmi = data[i].weight / (data[i].height/100) / (data[i].height/100);
  20. printf( "id %d : %.1f\n", data[i].id, data[i].bmi );
  21. }
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
id 1 : 20.8
id 2 : 22.2
id 3 : 21.9
id 4 : 21.6