Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //... matice.cpp
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main (int argc, char *argv[]) {
- unsigned int num = 0;
- srand (time(0)); //...Chceme opravdu nahodne cislo
- cout << "\nVitejte v programu pro vytvoreni ctvercove matice.\n";
- cout << "\nZadejte kladne prirozene cislo 1-X: "; //... Je nam celkem jedno jestli to je podle zadání více jak 10...
- cin >> num;
- cout << "\n\n";
- for (int i = 0; i < num; i++) {
- for (int j = 0; j < num; j++) {
- if (i == j) {
- if (i == (num-j-1))
- cout << "<" << rand()%9 << ">"; //...Stredovy bod bude ohranicen <X>
- else
- cout << "!" << rand()%9 << "!"; //...Hlavni diagonala
- } else
- if (i == (num-j-1))
- cout << "?" << rand()%9 << "?"; //...Vedlejsi diagonala
- else
- cout << " " << rand()%9 << " "; //...Ostatni cisla
- }
- cout << "\n";
- }
- return 0;
- }
- Input: 9
- Output:
- !8! 6 8 2 4 6 3 5 ?4?
- 8 !0! 5 4 1 1 1 ?0? 4
- 2 7 !4! 4 5 5 ?3? 8 1
- 1 5 7 !2! 4 ?4? 1 4 6
- 8 5 3 1 <2> 3 7 4 2
- 6 6 2 ?8? 6 !8! 2 1 4
- 5 2 ?3? 4 1 6 !3! 3 0
- 5 ?5? 2 3 2 6 6 !3! 8
- ?7? 8 2 0 6 8 1 3 !3!
Add Comment
Please, Sign In to add comment