daily pastebin goal
23%
SHARE
TWEET

cv2_ukol1.c

merkur32123 Feb 13th, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int
  6. main (int argc, char **argv)
  7. {
  8.   /* Matice. */
  9.   int mat[3][3];
  10.   int s_mat[5][3];
  11.  
  12.   /* Iteratory. */
  13.   unsigned int row;
  14.   unsigned int s_row;
  15.   unsigned int col;
  16.  
  17.   /* Determinant. */
  18.   int det;
  19.   int cast_det;
  20.  
  21.  
  22.   printf ("3x3 nahodna matice:\n\n");
  23.  
  24.   srand (time (NULL));
  25.   for (row = 0; row < 3; row++)
  26.     {
  27.       for (col = 0; col < 3; col++)
  28.         {  
  29.           mat[row][col] = (rand () % 199) - 99;
  30.           printf("%4d", mat[row][col]);
  31.         }
  32.       putchar ('\n');
  33.     }
  34.   putchar ('\n');
  35.  
  36.   /* Vypocet determinantu pomoci vzorce. */
  37.   det = mat[0][0] * mat[1][1] * mat[2][2]
  38.       + mat[0][1] * mat[1][2] * mat[2][0]
  39.       + mat[0][2] * mat[1][0] * mat[2][1]
  40.  
  41.       - mat[2][0] * mat[1][1] * mat[0][2]
  42.       - mat[2][1] * mat[1][2] * mat[0][0]
  43.       - mat[2][2] * mat[1][0] * mat[0][1];
  44.  
  45.   printf ("Determinant ziskan vzorcem: %d.\n\n\n", det);
  46.  
  47.   /* Vytvoreni Saurussovy matice. */
  48.   printf ("Saurussova matice:\n\n");
  49.   for (s_row = 0; s_row < 5; s_row++)
  50.     {
  51.       row = (s_row > 2) ? (s_row - 3) : s_row;
  52.       for (col = 0; col < 3; col++)
  53.         {
  54.           s_mat[s_row][col] = mat[row][col];
  55.           printf("%4d", s_mat[s_row][col]);
  56.         }
  57.       putchar ('\n');
  58.     }
  59.   putchar ('\n');
  60.  
  61.   /* Vypocet determinantu Saurussovim pravidlem. */
  62.   det = 0;
  63.   for (s_row = 0; s_row < 3; s_row++)
  64.     {
  65.       /* Zacinajic v bode [s_row][0], znasobit diagonalni prvky smerem dolu. */
  66.       for (row = s_row, col = 0, cast_det = 1;
  67.            col < 3;
  68.            row++, col++)
  69.         {
  70.           cast_det *= s_mat[row][col];
  71.         }
  72.       det += cast_det;
  73.     }
  74.   for (s_row = 4; s_row > 1; s_row--)
  75.     {
  76.       /* Zacinajic v bode [s_row][0], znasobit diagonalni prvky smerem nahoru. */
  77.       for (row = s_row, col = 0, cast_det = 1;
  78.            col < 3;
  79.            row--, col++)
  80.         {
  81.           cast_det *= s_mat[row][col];
  82.         }
  83.       det -= cast_det;
  84.     }
  85.  
  86.   printf ("Determinant ziskan Saurussovim pravidlem: %d.\n\n\n", det);
  87.  
  88.   printf ("Zmacknite Enter pro ukonceni programu... ");
  89.   getchar ();
  90.  
  91.   return 0;
  92. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top