Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int num;
- cin >> num;
- int counter = 1;
- for (int row = 1; row <= num; row++) {
- for (int col = 0; col < row; col++) {
- if (counter > num) {
- break;
- }
- cout << counter << " ";
- counter++;
- }
- if (counter > num) {
- break;
- }
- cout << endl;
- }
- return 0;
- }
- Или:
- #include <iostream>
- using namespace std;
- int main() {
- int num;
- cin >> num;
- int counter = 1;
- for (int row = 1; row <= num || counter <= num; row++) {
- for (int col = 0; col < row && counter <= num; col++) {
- cout << counter << " ";
- counter++;
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement