Advertisement
Guest User

Array Bidimensionale

a guest
Apr 26th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define SETTIMANA 7
  5. #define SOGGETTI 5
  6.  
  7. void CalorieObesi(float calor[SOGGETTI][SETTIMANA]);
  8. void totaleCalorie(float calor[SOGGETTI][SETTIMANA]);
  9.  
  10. int main(int argc, char *argv[]) {
  11.     float calorie[SOGGETTI][SETTIMANA]={0};
  12.     float media_calorie;
  13.    
  14.     CalorieObesi(calorie);
  15.     totaleCalorie(calorie);
  16.    
  17.     return 0;
  18. }
  19.  
  20. void CalorieObesi(float calor[SOGGETTI][SETTIMANA]){
  21.     int i, k;
  22.     for (i=0; i<SETTIMANA; i++){
  23.         printf("--GIORNO %d--\n", i+1);
  24.        
  25.         for(k=0; k<SOGGETTI; k++){
  26.             printf("Inserisca le calorie del soggetto %d: \t\t", k+1);
  27.             scanf("%f", &calor[k][i]);
  28.         }
  29.     }
  30. }
  31.  
  32. void totaleCalorie(float calor[SOGGETTI][SETTIMANA]){
  33.     int i, k=0;
  34.     float totale=0;
  35.     for(i=0;i<SOGGETTI; i++){
  36.        
  37.         printf("--SOGGETTO %d--\n",i+1);
  38.         printf("--Calcolo totale calorie del soggetto %d\n", k+1);
  39.         for(k=0; k<SETTIMANA;k++){
  40.             totale=totale+calor[i][k];
  41.         }
  42.         printf("TOTALE CALORIE SETTIMANA: %.2lf\n", totale);
  43.         printf("MEDIA CALORIE ASSUNTE NELLA SETTIMANA: %.2lf\n", totale/7);
  44.         printf("------------------------\n");
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement