grach

Sequence_2k Plus1

Jul 19th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Sequence_2kPlus1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             int num = 1;
  15.  
  16.             while (num <= n) // отпеччатваме докато не стигнем n (горната ни граница)
  17.             {
  18.                 Console.WriteLine(num);
  19.  
  20.                 num = 2 * num + 1; // когато num стигне стойност = 2 * num + 1 излизаме от цикъла
  21.             }
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment