Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace NumberPyramid
- {
- class Program
- {
- static void Main(string[] args)
- {
- int num = int.Parse(Console.ReadLine());
- int counter = 1;
- for (int row = 1; row <= num; row++)
- {
- for (int col = 0; col < row; col++)
- {
- if (counter > num)
- {
- break;
- }
- Console.Write(counter + " ");
- counter++;
- }
- if (counter > num)
- {
- break;
- }
- Console.WriteLine();
- }
- }
- }
- }
- ИЛИ:
- using System;
- namespace NumberPyramid
- {
- class Program
- {
- static void Main(string[] args)
- {
- int num = int.Parse(Console.ReadLine());
- int counter = 1;
- for (int row = 1; row <= num || counter <= num; row++)
- {
- for (int col = 0; col < row && counter <= num; col++)
- {
- Console.Write(counter++ + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment