Advertisement
Filkolev

Calculate Sequence

Jul 16th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. namespace _02.CalculateSequence
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.  
  6.     public class CalculateSequence
  7.     {
  8.         public static void Main()
  9.         {
  10.             const int NumberOfElementsToShow = 50;
  11.  
  12.             int currentNumber = int.Parse(Console.ReadLine());
  13.             Queue<int> sequence = new Queue<int>();
  14.  
  15.             int countOfNumbersPrinted = 0;
  16.             while (countOfNumbersPrinted < NumberOfElementsToShow)
  17.             {
  18.                 sequence.Enqueue(currentNumber + 1);
  19.                 sequence.Enqueue((2 * currentNumber) + 1);
  20.                 sequence.Enqueue(currentNumber + 2);
  21.                
  22.                 Console.Write(currentNumber);
  23.                 if (countOfNumbersPrinted < NumberOfElementsToShow - 1)
  24.                 {
  25.                     Console.Write(", ");
  26.                 }
  27.  
  28.                 currentNumber = sequence.Dequeue();
  29.                 countOfNumbersPrinted++;
  30.             }
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement