Guest User

Untitled

a guest
Feb 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. #define N 12
  6.  
  7. int main(){
  8. int s,i,j,l,m,n,k,mes[];
  9. float temp[],temp_med[];
  10.  
  11. FILE*df_in,*df_out;
  12.  
  13. df_in=fopen("temperaturas.txt","r");
  14. df_out=fopen("temp_med.txt","w");
  15. if(df_in==NULL || df_out==NULL){
  16. printf("error abriendo el fichero");
  17. system ("PAUSE");
  18. return -1;
  19. }
  20. i=1;
  21. s=0;
  22. while(fscanf(df_in,"%d%f",&mes[l],&temp[m])!=EOF{
  23. if(mes[l]==i){
  24. s+=temp[m];
  25. j++}
  26. if(mes[l]>i){
  27. temp_med[n]=s/j;
  28. j=0;
  29. i++;
  30. n++;}
  31. l++;
  32. m++;
  33. }
  34. for(k=1;k<=12;k++)
  35. fprintf(df_out,"%d%f\n",k,temp_med[k]);
  36. fclose(df_in,df_out);
  37. system ("PAUSE");
  38. return 0;
  39. }
Add Comment
Please, Sign In to add comment