Advertisement
domdealm

Questão - Temperaturas

Jan 25th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.95 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #define t_emp 20
  4.  
  5. void media(float *vetor,int z,float *result);
  6. void temp_max(float *vetor_1, int z_1, float *tmx);
  7. void temp_min(float *vetor_2, int z_2, float *tmn);
  8. int acima(float *vetor_3,int tam,float *mid);
  9. int abaixo(float *vetor_4,int tam1,float *mid1);
  10.  
  11. int main(){
  12.     float temp[t_emp];
  13.     int i,i_a,i_b;
  14.     float res_m,max_temp,min_temp;
  15.     FILE *temper;
  16.     temper = fopen("temperat.txt","r");
  17.     for(i=0;i<t_emp;i++){
  18.         fscanf(temper,"%f\n",&temp[i]);
  19.     }
  20.     media(temp,t_emp,&res_m);// como temp é um vetor, não precisa do asterisco
  21.     printf("Media de temperaturas: %g \n",res_m);//   no parâmetro da função
  22.     temp_max(temp,t_emp,&max_temp);
  23.     printf("Maior temperatura: %g \n",max_temp);
  24.     temp_min(temp,t_emp,&min_temp);
  25.     printf("Menor temperatura: %g \n",min_temp);
  26.     i_a = acima(temp,t_emp,&res_m);
  27.     i_b = abaixo(temp,t_emp,&res_m);
  28.     printf("Quantas temperatas estao acima da media: %d \n",i_a);
  29.     printf("Quantas temperatas estao abaixo da media: %d \n",i_b);
  30.     fclose(temper);
  31.  
  32.  
  33.     //fflush(stdin); windows
  34.     getchar();
  35.     return 0;
  36.  
  37. }
  38.  
  39. void media(float *vetor,int z,float *result){
  40.     int count_z;
  41.     float m_aux=0;
  42.     for(count_z = 0; count_z < z; count_z++){
  43.         m_aux += vetor[count_z];
  44.     }
  45.     *result = m_aux/z;
  46. }
  47.  
  48. void temp_max(float *vetor_1, int z_1, float *tmx){
  49.     int cont_z1;
  50.     *tmx = 0;
  51.     for(cont_z1 = 0; cont_z1 < z_1; cont_z1++){
  52.         if (vetor_1[cont_z1] > *tmx){
  53.             *tmx = vetor_1[cont_z1];
  54.         }
  55.  
  56.     }
  57. }
  58.  
  59. void temp_min(float *vetor_2, int z_2, float *tmn){
  60.     int cont_z2;
  61.     *tmn = 39.7;
  62.     for(cont_z2 = 0; cont_z2 < z_2; cont_z2++){
  63.         if (vetor_2[cont_z2] < *tmn){
  64.             *tmn = vetor_2[cont_z2];
  65.         }
  66.  
  67.     }
  68. }
  69. int acima(float *vetor_3,int tam,float *mid){
  70.     int k=0,l=0;
  71.     for(k=0;k<tam;k++){
  72.         if(vetor_3[k] > *mid){
  73.             l++;
  74.         }
  75.     }
  76.     return l;
  77. }
  78. int abaixo(float *vetor_4,int tam1,float *mid1){
  79.     int j=0,n=0;
  80.     for(j=0;j<tam1;j++){
  81.         if(vetor_4[j] < *mid1){
  82.             n++;
  83.         }
  84.     }
  85.     return n;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement