Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #define N 12
- int main(){
- int s,i,j,l,m,n,k,mes[];
- float temp[],temp_med[];
- FILE*df_in,*df_out;
- df_in=fopen("temperaturas.txt","r");
- df_out=fopen("temp_med.txt","w");
- if(df_in==NULL || df_out==NULL){
- printf("error abriendo el fichero");
- system ("PAUSE");
- return -1;
- }
- i=1;
- s=0;
- while(fscanf(df_in,"%d%f",&mes[l],&temp[m])!=EOF{
- if(mes[l]==i){
- s+=temp[m];
- j++}
- if(mes[l]>i){
- temp_med[n]=s/j;
- j=0;
- i++;
- n++;}
- l++;
- m++;
- }
- for(k=1;k<=12;k++)
- fprintf(df_out,"%d%f\n",k,temp_med[k]);
- fclose(df_in,df_out);
- system ("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment