Advertisement
Waliul

Solution 1

Oct 25th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int arr[50], var, x, p, num, m;
  5.     printf("Enter the position : ");
  6.     scanf("%d", &p);
  7.     printf("Enter the number : ");
  8.     scanf("%d", &x);
  9.     FILE *fp, *fpw;
  10.     fp = fopen("F:\\inputr.txt", "r");
  11.     fpw = fopen("F:\\outputr.txt", "w");
  12.     int i = 0, j = 0;
  13.     while(fscanf(fp,"%d",&arr[i])!=EOF)
  14.     {
  15.         i++;
  16.     }
  17.     for(j=i; j>=p-1; j--)
  18.     {
  19.         arr[j]=arr[j-1];
  20.     }
  21.     arr[p-1]=x;
  22.     for(j=0; j<=i; j++)
  23.     {
  24.         num = arr[j];
  25.         while(num != 0)
  26.         {
  27.             m = num % 10;
  28.             num = num / 10;
  29.         }
  30.         fprintf(fpw, "%d ", m);
  31.     }
  32.     fclose(fp);
  33.     fclose(fpw);
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement