Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Linq;
- using System.Collections.Generic;
- using System;
- namespace SortedIterativeWay
- {
- class Program
- {
- static int[] array;
- static int arrLen;
- static int iterations;
- public static void Main(string[] args)
- {
- iterations = int.Parse(Console.ReadLine());
- arrLen = int.Parse(Console.ReadLine());
- array = new int[arrLen];
- InitTheArr();
- NestedLoops();
- }
- static void NestedLoops()
- {
- while (true)
- {
- PrintRow();
- int currentPosition = array.Length - 1;
- array[currentPosition]++;
- while (array[currentPosition] > iterations)
- {
- if (currentPosition - 1 >= 0)
- {
- array[currentPosition] = array[currentPosition - 1];
- }
- currentPosition--;
- if (currentPosition < 0)
- {
- return;
- }
- array[currentPosition]++;
- if (currentPosition + 1 <= array.Length && array[currentPosition] > iterations)
- {
- array[currentPosition + 1] = iterations;
- }
- else if (currentPosition + 1 <= array.Length && array[currentPosition] <= iterations)
- {
- array[currentPosition + 1] = array[currentPosition];
- }
- }
- }
- }
- static void PrintRow()
- {
- Console.WriteLine(string.Join(" ", array));
- }
- static void InitTheArr()
- {
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = 1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment