C code: #include int main(void) { FILE *infp, *outfp; int ID,day,hr,i=1; int Temp_ID,Total_hr; int Line_No=0; if ((infp = fopen(\"emp.txt\", \"r\"))==NULL) { printf(\"Input file cannot be opened\ \"); return-1; } if ((outfp = fopen(\"out.txt\", \"w\"))==NULL) { printf(\"Output file cannot be opened\ \"); return-1; } while(!feof(infp)) { Line_No=Line_No+1; fscanf(infp,\"%d %d\",&ID,&hr); if(Line_No==1) { Temp_ID=ID;day=1;Total_hr=hr; } else { if(Temp_ID==ID) { day=day+1; Total_hr=Total_hr+hr; } else { fprintf(outfp,\"%d %d %d\ \",Temp_ID,day,Total_hr); Temp_ID=ID;day=1;Total_hr=hr; } } } fprintf(outfp,\"%d %d %d\ \",Temp_ID,day-1,Total_hr-hr); fclose(infp); fclose(outfp); } emp.txt: 11 2 11 8 11 5 15 10 18 4 18 16 20 23 20 11 out.txt: 11 3 15 15 1 10 18 2 20 20 2 34 Solution C code: #include int main(void) { FILE *infp, *outfp; int ID,day,hr,i=1; int Temp_ID,Total_hr; int Line_No=0; if ((infp = fopen(\"emp.txt\", \"r\"))==NULL) { printf(\"Input file cannot be opened\ \"); return-1; } if ((outfp = fopen(\"out.txt\", \"w\"))==NULL) { printf(\"Output file cannot be opened\ \"); return-1; } while(!feof(infp)) { Line_No=Line_No+1; fscanf(infp,\"%d %d\",&ID,&hr); if(Line_No==1) { Temp_ID=ID;day=1;Total_hr=hr; } else { if(Temp_ID==ID) { day=day+1; Total_hr=Total_hr+hr; } else { fprintf(outfp,\"%d %d %d\ \",Temp_ID,day,Total_hr); Temp_ID=ID;day=1;Total_hr=hr; } } } fprintf(outfp,\"%d %d %d\ \",Temp_ID,day-1,Total_hr-hr); fclose(infp); fclose(outfp); } emp.txt: 11 2 11 8 11 5 15 10 18 4 18 16 20 23 20 11 out.txt: 11 3 15 15 1 10 18 2 20 20 2 34.