Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #define mMax 10
  5. #define nMax 10
  6. int i, j;
  7. int m = 10; int n = 10;
  8. void Input(int A[mMax][nMax],int m, int n)
  9. {
  10.     FILE *fileInput;
  11.     errno_t err = fopen_s(&fileInput, "Output1.txt", "w");
  12.     if (err)
  13.     {
  14.         printf_s("File not open");
  15.         system("pause");
  16.         return;
  17.     }
  18.     else
  19.     {
  20.         printf_s("\n Enter m and n: ");
  21.         scanf_s("%d%d", &m, &n);
  22.         for (i = 0; i < m; i++)
  23.         {
  24.             for (j = 0; j < n; j++)
  25.             {
  26.                 fscanf_s(fileInput, "%d", &A[m][n]);
  27.             }
  28.         }
  29.     }
  30.     fclose(fileInput);
  31. }
  32. int fact(int f)
  33. {
  34.     int s;
  35.     for (s = 1; f>0; f--)
  36.     {
  37.         s = s*f;
  38.     }
  39.     return s;
  40. }
  41. int C(int i, int j)
  42. {
  43.     if (j>i)
  44.     {
  45.         int per = j;
  46.         j = i;
  47.         i = per;
  48.     }
  49.     return fact(i) / (fact(j)*fact(i - j));
  50. }
  51. void Output(int A[mMax][nMax])
  52. {
  53.     FILE *fileOutput;
  54.     errno_t err = fopen_s(&fileOutput, "Output1.txt", "w+");
  55.     if (err)
  56.     {
  57.         printf_s("File not open");
  58.         system("pause");
  59.         return;
  60.     }
  61.     for (i = 0; i < m; i++)
  62.     {
  63.         for (j = 0; j < n; j++)
  64.         {
  65.             fprintf(fileOutput, "%d", A[m][n]);
  66.             printf_s("%d", A[m][n]);
  67.         }
  68.         fprintf(fileOutput, "\n");
  69.         puts(" ");
  70.     }
  71.     fclose(fileOutput);
  72. }
  73. int main()
  74. {
  75.     int A[mMax][nMax];
  76.     for (i = 0; i<m; i++)
  77.     {
  78.         A[i][i] = C(i + 1, i + 1);
  79.         j = i + 1;
  80.         while (j<n)
  81.         {
  82.             if (i >= j)
  83.             {
  84.                 A[i][j] = A[j][i] = C(j + 1, i + 1);
  85.             }
  86.             else
  87.             {
  88.                 A[j][i] = A[i][j] = C(j + 1, i + 1);
  89.             }
  90.             j++;
  91.         }
  92.     }
  93.     for (i = 0; i<m; i++)
  94.     {
  95.         for (j = 0; j<n; j++)
  96.         {
  97.             printf("%d\t", A[i][j]);
  98.         }
  99.         printf("\n");
  100.     }
  101.     _getch();
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement