Advertisement
Stybyk

ALG -2.uhly

Nov 19th, 2014
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <stdlib.h>
  4.  
  5. using namespace std;
  6.  
  7. const int N = 5;
  8.  
  9. void naplneni(double **pole, const int N)
  10. {
  11.         for (int i = 0; i < N; i++)
  12.         {
  13.                 for (int j = 0; j < N; j++)
  14.                 {
  15.                         pole[i][j] = rand() % 100;
  16.                 }
  17.         }
  18. }
  19.  
  20. void tisk( double **pole ,const int N)
  21. {
  22.         for (int i = 0; i < N; i++)
  23.         {
  24.                 for (int j = 0; j < N; j++)
  25.                 {
  26.                        
  27.                         cout << pole[i][j] << "\t" ;
  28.                 }
  29.                 cout << endl;
  30.         }
  31. }
  32.  
  33. void vypocet(double **pole, const int N )
  34. {
  35.         double prevyseni, D, uhel_sklonu;
  36.        
  37.  
  38.         for (int i = 1; i < N-1; i++)
  39.         {
  40.             double tmp = 10 ;
  41.                 for (int j = 1; j < N - 1; j++)
  42.                 {
  43.                         for (int k = i-1; k <= i+1; k++)
  44.                         {
  45.                                 for (int l = j-1; l <= j+1; l++)
  46.                                 {
  47.                                         if ((k != i) || (l != j) )
  48.                                         {
  49.                                                 prevyseni = pole[i][j] - pole[k][l];
  50.                                                
  51.                                                 D = (i - k)*(i - k) + (j - l)*(j - l);
  52.                                                 D = sqrt(D);
  53.                                                 uhel_sklonu = prevyseni / D;
  54.                                                 uhel_sklonu = atan(uhel_sklonu);
  55.  
  56.  
  57.  
  58.                                                 cout << uhel_sklonu << "\t" ;
  59.                                                
  60.  
  61.                                                 if (uhel_sklonu < tmp)
  62.                                                 {
  63.                                                         tmp = uhel_sklonu;
  64.                                                 }
  65.                                         }
  66.  
  67.                                         else  cout << "\t" ;
  68.  
  69.  
  70.                                 } cout << endl;
  71.                                
  72.                         }       cout << "Nejmensi uhel sklonu je: " << tmp << endl;
  73.                                 cout << endl;
  74.                                              
  75.                 }
  76.         }
  77. }
  78.  
  79. int main()
  80. {
  81.         double **pole = new double*[N];
  82.         for (int i = 0; i < N; i++)
  83.         {
  84.                 pole[i] = new double[N];
  85.         }
  86.         srand(time(NULL));
  87.         naplneni(pole,N);
  88.         tisk(pole ,N);
  89.         cout << endl;
  90.         vypocet(pole ,N);
  91.  
  92.  
  93.         for (int i = 0; i < N; i++)
  94.         {
  95.                 delete[]pole[i];
  96.         }
  97.         delete[]pole;
  98.         cin.get();
  99.         return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement