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