Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Program koji ispisuje brojeve do n (n<=210) na ovakav način:
- 1 3 4 10 11 21 22 36
- 2 5 9 12 20 23 35
- 6 8 13 19 24 34
- 7 14 18 25 33
- 15 17 26 32
- 16 27 31
- 28 30
- 29 */
- #include <iostream>
- #include <cmath>
- using namespace std;
- main()
- {
- int n, a[210][210];
- cin >> n;
- for (int i=0; i<sqrt(n*2); i++)
- for (int j=0; j<sqrt(n*2); j++)
- a[i][j] = 0;
- a[0][0] = 1;
- for (int i=1; i<sqrt(n*2); i++)
- if (i%2==1)
- a[i][0] = a[i-1][0] + 1;
- else
- a[i][0] = a[i-1][0] + 4*(i/2);
- for (int i=1; i<sqrt(n*2); i++)
- if (i%2==1)
- a[0][i] = a[0][i-1] + i*2;
- else
- a[0][i] = a[0][i-1] + 1;
- for (int i=1; i<sqrt(n*2); i++)
- for (int j=1; j<sqrt(n*2); j++)
- a[i][j] = a[i-1][j-1] + (i+j)*2;
- for (int i=0; i<sqrt(n*2); i++)
- {
- for (int j=0; j<sqrt(n*2); j++)
- if ((a[i][j] != 0)&&(i+j<sqrt(n*2))&&(a[i][j] <= n))
- if (a[i][j]<10)
- cout << " " << a[i][j] << " ";
- else if (a[i][j]<100)
- cout << " " << a[i][j] << " ";
- else
- cout << a[i][j] << " ";
- cout << endl;
- }
- system ("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment