Advertisement
Warmcold

masynwe obliczenia lol

Feb 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main(int argc, char *argv[]){
  6.     double **A,**B,**C;
  7.     double suma,suma_kontrolna;
  8.     int rows;
  9.     clock_t begin_t,end_t;
  10.     int i,j,k;
  11.    
  12.     rows=atoi(argv[1]);
  13.    
  14.     //inicjujemy macierze
  15.    
  16.     A=(double**)malloc(rows * sizeof(double*));
  17.     B=(double**)malloc(rows * sizeof(double*));
  18.     C=(double**)malloc(rows * sizeof(double*));
  19.    
  20.     for(i=0; i < rows; i++){
  21.         A[i] = (double*)malloc(rows * sizeof(double));
  22.         B[i] = (double*)malloc(rows * sizeof(double));
  23.         C[i] = (double*)malloc(rows * sizeof(double));
  24.     }
  25.  
  26. //wypelnaimy macierze wartosciami
  27.  
  28.     for(i=0; i < rows; i++){
  29.         for(j=0; j < rows; j++){
  30.         A[i][j] = (double)(1 + i * rows +j);
  31.         B[i][j] = (double)(1 + i * rows +j +rows*rows);
  32.         }
  33.     }
  34.  
  35.  
  36.     printf("A: %f %f \n",A[0][0],A[0][1]);
  37.     printf("A: %f %f \n",A[1][0],A[1][1]);
  38.  
  39.     printf("B: %f %f \n",B[0][0],B[0][1]);
  40.     printf("B: %f %f \n",B[1][0],B[1][1]);
  41.  
  42.     begin_t=clock();
  43.  
  44.     for(i=0; i<rows; i++){
  45.        for(j=0; j<rows; j++){
  46.                C[i][j]=0;
  47.                for(=0; k<rows; k++){
  48.                   C[i][j] += A[i][k] * B[k][j];
  49.                }
  50.            }
  51.         }
  52.         end_t=clock();
  53.  
  54.  
  55.     printf("C: %f %f \n",C[0][0],C[0][1]);
  56.     printf("C: %f %f \n",C[1][0],C[1][1]);
  57.     printf("\n");
  58.  
  59.     suma_kontrolna=0;
  60.     for(i=0;i<rows; i++){
  61.    
  62.     }
  63. }
  64. //kompilacja:
  65. //gcc program.c -o progrx
  66. //uruchomienie
  67. //./progrx rows
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement