Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- //пример входного файла: 1 2 0 -1 -3 0 -100 0 0 200 -3 5555 100 20 0
- //то что будет на выходе: 1 2 5555 -1 -3 5555 -100 5555 5555 200 -3 5555 100 20 5555
- int FUNC(void) {
- FILE* h;
- int n=15,i,max,k=0;
- int a[15];
- h=fopen("D:\\in.txt","r"); //положим файл "in.txt" в корень диска Z.
- for(i=0;i<n;i++) fscanf(h,"%d",&a[i]);
- fclose(h);
- max=0;
- for(i=1;i<n;i++) if(abs(a[max])<abs(a[i])) max=i;
- for(i=0;i<n;i++) if(a[i]==0) {a[i]=a[max]; k++;}
- h=fopen("D:\\out.txt","w");
- for(i=0;i<n;i++) fprintf(h,"%d ",a[i]);
- fclose(h);
- return k; //вернем количество элементов заменнных.
- }
- int main() {
- printf("%d",FUNC());
- }
Advertisement
Add Comment
Please, Sign In to add comment