Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <time.h>
- #include <locale.h>
- #define ON 1
- #define OFF 0
- #define DEBUG OFF
- #if DEBUG == ON
- #define debug(msg) printf ("%i\n", msg);
- #else
- #define debug(msg)
- #endif
- int main(void) {
- setlocale(LC_ALL,"");
- unsigned m, n, i, j, k, l;
- printf ("Введите m и n:\n");
- scanf("%d %d",&m,&n);
- float **result;
- result = (float**)malloc(n*m * sizeof(float*));
- for (i = 0; i < m; i++){
- result[i] = (int*) malloc (m * sizeof(int));
- }
- int **a;
- a = (int**)malloc(n*m * sizeof(int*));
- for (i = 0; i < m; i++){
- a[i] = (int*) malloc (m * sizeof(int));
- }
- int string, column;
- srand ( time(NULL) );
- for (i = 0; i < m; i++) {
- for (j = 0; j < n; j++){
- a[i][j] = rand()%10;
- printf("a[%d][%d] = %d\t", i, j, a[i][j]);
- }
- printf( "\n" );
- }
- int **arrstring;
- arrstring = (int**)malloc(n*m * sizeof(int*));
- for (i = 0; i < m; i++){
- arrstring[i] = (int*) malloc (m * sizeof(int));
- }
- for (i = 0; i < m; i++) {
- for (j = 0; j < n; j++){
- arrstring[i][j] = 0;
- //printf("arrstring[%d][%d] = %d\t", i, j, arrstring[i][j]);
- }
- printf( "\n" );
- }
- int **arrcolumn;
- arrcolumn = (int**)malloc(n*m * sizeof(int*));
- for (i = 0; i < m; i++){
- arrcolumn[i] = (int*) malloc (m * sizeof(int));
- }
- string = 0; column = 0;
- for (i = 0; i < m; i++){
- for (j = 0; j < n; j++){
- for (l = 0; l < n; l++){
- string = string + a[i][l];
- }
- string = string - a[i][j]; debug(string);
- arrstring[i][j] = string;
- //printf ("string[%d][%d] = %d\n", i, j, arrstring[i][j]);
- string = 0;
- }
- }
- for (i = 0; i < n; i++){
- for (j = 0; j < n; j++){
- for (k = 0; k < m; k++){
- column = column + a[k][j];
- }
- column = column - a[i][j];
- arrcolumn[i][j] = column;
- //printf ("column[%d][%d] = %d\n", i, j, arrcolumn[i][j]);
- column = 0;
- }
- }
- for (i = 0; i < n; i++){
- for (j = 0; j < n; j++){
- result [i][j] = (arrstring [i][j] * 1.0) / (arrcolumn[i][j] * 1.0);
- printf ("result[%d][%d] = %.2f\t", i, j, result [i][j]);
- }
- puts("");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement