Hellko

cc

Dec 26th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. //пример входного файла: 1 2 0 -1 -3 0 -100 0 0 200 -3 5555 100 20 0
  4. //то что будет на выходе: 1 2 5555 -1 -3 5555 -100 5555 5555 200 -3 5555 100 20 5555
  5.  
  6.  
  7. int FUNC(void) {
  8. FILE* h;
  9. int n=15,i,max,k=0;
  10. int a[15];
  11. h=fopen("D:\\in.txt","r"); //положим файл "in.txt" в корень диска Z.
  12. for(i=0;i<n;i++) fscanf(h,"%d",&a[i]);
  13. fclose(h);
  14. max=0;
  15. for(i=1;i<n;i++) if(abs(a[max])<abs(a[i])) max=i;
  16. for(i=0;i<n;i++) if(a[i]==0) {a[i]=a[max]; k++;}
  17.  
  18. h=fopen("D:\\out.txt","w");
  19. for(i=0;i<n;i++) fprintf(h,"%d ",a[i]);
  20. fclose(h);
  21. return k; //вернем количество элементов заменнных.
  22. }
  23.  
  24. int main() {
  25. printf("%d",FUNC());
  26. }
Advertisement
Add Comment
Please, Sign In to add comment