Advertisement
kiraventom

Юра лаба 7

Dec 18th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <locale.h>
  6.  
  7. #define ON 1
  8. #define OFF 0
  9.  
  10. #define DEBUG OFF
  11.  
  12. #if DEBUG == ON
  13.     #define debug(msg) printf ("%i\n", msg);
  14. #else
  15.     #define debug(msg)
  16. #endif
  17.  
  18.  
  19. int main(void) {
  20.  
  21.     setlocale(LC_ALL,"");
  22.     unsigned m, n, i, j, k, l;
  23.     printf ("Введите m и n:\n");
  24.     scanf("%d %d",&m,&n);
  25.  
  26.  
  27.     float **result;
  28.     result = (float**)malloc(n*m * sizeof(float*));
  29.     for (i = 0; i < m; i++){
  30.         result[i] = (int*) malloc (m * sizeof(int));
  31.     }
  32.  
  33.  
  34.     int **a;
  35.     a = (int**)malloc(n*m * sizeof(int*));
  36.     for (i = 0; i < m; i++){
  37.         a[i] = (int*) malloc (m * sizeof(int));
  38.     }
  39.  
  40.     int string, column;
  41.  
  42.     srand ( time(NULL) );
  43.     for (i = 0; i < m; i++) {
  44.         for (j = 0; j < n; j++){
  45.             a[i][j] = rand()%10;
  46.             printf("a[%d][%d] = %d\t", i, j, a[i][j]);
  47.  
  48.         }
  49.     printf( "\n" );
  50.     }
  51.  
  52.     int **arrstring;
  53.     arrstring = (int**)malloc(n*m * sizeof(int*));
  54.     for (i = 0; i < m; i++){
  55.         arrstring[i] = (int*) malloc (m * sizeof(int));
  56.     }
  57.  
  58.     for (i = 0; i < m; i++) {
  59.         for (j = 0; j < n; j++){
  60.             arrstring[i][j] = 0;
  61.             //printf("arrstring[%d][%d] = %d\t", i, j, arrstring[i][j]);
  62.  
  63.         }
  64.         printf( "\n" );
  65.     }
  66.  
  67.     int **arrcolumn;
  68.     arrcolumn = (int**)malloc(n*m * sizeof(int*));
  69.     for (i = 0; i < m; i++){
  70.         arrcolumn[i] = (int*) malloc (m * sizeof(int));
  71.     }
  72.  
  73.  
  74.     string = 0; column = 0;
  75.  
  76.     for (i = 0; i < m; i++){
  77.         for (j = 0; j < n; j++){
  78.             for (l = 0; l < n; l++){
  79.                 string = string + a[i][l];
  80.             }
  81.         string = string - a[i][j]; debug(string);
  82.         arrstring[i][j] = string;
  83.         //printf ("string[%d][%d] = %d\n", i, j, arrstring[i][j]);
  84.         string = 0;
  85.         }
  86.     }
  87.  
  88.  
  89.  
  90.     for (i = 0; i < n; i++){
  91.         for (j = 0; j < n; j++){
  92.             for (k = 0; k < m; k++){
  93.                 column = column + a[k][j];
  94.             }
  95.             column = column - a[i][j];
  96.             arrcolumn[i][j] = column;
  97.             //printf ("column[%d][%d] = %d\n", i, j, arrcolumn[i][j]);
  98.             column = 0;
  99.         }
  100.     }
  101.     for (i = 0; i < n; i++){
  102.         for (j = 0; j < n; j++){
  103.             result [i][j] = (arrstring [i][j] * 1.0) / (arrcolumn[i][j] * 1.0);
  104.             printf ("result[%d][%d] = %.2f\t", i, j, result [i][j]);
  105.         }
  106.         puts("");
  107.     }
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement