hercioneto

Exercício Pessoas + IMC

Dec 21st, 2023 (edited)
1,415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1. // Online C compiler to run C program online
  2. #include <stdio.h>
  3.  
  4. typedef struct // Cria uma STRUCT para armazenar os dados de uma pessoa
  5.  
  6. {
  7.    char Nome[50];
  8.     int Idade;
  9.     float Peso;
  10.     float Altura;
  11.     float Imc;
  12.  
  13. } Pessoa; // Define o nome do novo tipo criado
  14.  
  15. void ImprimePessoa(Pessoa P) // declara o parâmetro como uma struct
  16.  
  17. {
  18.  
  19.   printf("Nome: %s Idade: %d  Peso: %f Altura: %f IMC: %f \n",P.Nome, P.Idade, P.Peso, P.Altura, P.Imc);
  20.  
  21. }
  22.  
  23. int main()
  24.  
  25. {
  26.  
  27.     Pessoa Povo[10];
  28.     char nome[50];
  29.     float somaIMC=0;
  30.     float mediaIMC=0;
  31.    for (int i = 0 ; i<=1; i++) {
  32.        printf("Digite o nome da pessoa %i: ",i+1);
  33.        scanf("%s",&Povo[i].Nome);
  34.        printf("Digite a altura da pessoa %i: ",i+1);
  35.        scanf("%f",&Povo[i].Altura);
  36.        printf("Digite peso da pessoa %i: ",i+1);
  37.        scanf("%f",&Povo[i].Peso);
  38.        Povo[i].Imc = (Povo[i].Peso / (Povo[i].Altura * Povo[i].Altura));
  39.        somaIMC = somaIMC + Povo[i].Imc;
  40.     }
  41.     for (int i = 0 ; i<=1; i++) {
  42.     ImprimePessoa(Povo[i]);
  43.     }
  44.     mediaIMC = somaIMC / 2;
  45.     printf("Media de IMCs %f: ",mediaIMC);
  46.  
  47.  
  48.    return 0;
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment