seberm

seberm

Apr 24th, 2009
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. //... matice.cpp
  2.  
  3. #include <iostream>
  4. #include <cstdlib>
  5. #include <ctime>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main (int argc, char *argv[]) {
  11.     unsigned int num = 0;
  12.    
  13.     srand (time(0)); //...Chceme opravdu nahodne cislo
  14.    
  15.     cout << "\nVitejte v programu pro vytvoreni ctvercove matice.\n";
  16.     cout << "\nZadejte kladne prirozene cislo 1-X: "; //... Je nam celkem jedno jestli to je podle zadání více jak 10...
  17.     cin >> num;
  18.     cout << "\n\n";
  19.  
  20.     for (int i = 0; i < num; i++) {
  21.         for (int j = 0; j < num; j++) {
  22.             if (i == j) {
  23.                 if (i == (num-j-1))
  24.                     cout << "<" << rand()%9 << ">"; //...Stredovy bod bude ohranicen <X>
  25.                 else
  26.                     cout << "!" << rand()%9 << "!"; //...Hlavni diagonala
  27.                    
  28.             } else
  29.                 if (i == (num-j-1))
  30.                     cout << "?" << rand()%9 << "?"; //...Vedlejsi diagonala
  31.                 else
  32.                     cout << " " << rand()%9 << " "; //...Ostatni cisla
  33.         }
  34.  
  35.         cout << "\n";
  36.     }
  37.  
  38.     return 0;
  39. }
  40.  
  41.  
  42. Input: 9
  43.  
  44.  
  45. Output:
  46.  
  47. !8! 6  8  2  4  6  3  5 ?4?
  48.  8 !0! 5  4  1  1  1 ?0? 4
  49.  2  7 !4! 4  5  5 ?3? 8  1
  50.  1  5  7 !2! 4 ?4? 1  4  6
  51.  8  5  3  1 <2> 3  7  4  2
  52.  6  6  2 ?8? 6 !8! 2  1  4
  53.  5  2 ?3? 4  1  6 !3! 3  0
  54.  5 ?5? 2  3  2  6  6 !3! 8
  55. ?7? 8  2  0  6  8  1  3 !3!
  56.  
Add Comment
Please, Sign In to add comment