Advertisement
cortez

Print Long Sequence

Aug 27th, 2015
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Problem_16__PrintLongSequence
  4. {
  5.     class PrintLongSequence
  6.     {
  7.         public static void Main ()
  8.         {
  9.             Console.WriteLine ("Please enter the length of the sequence:");
  10.             int len;
  11.             string input = Console.ReadLine ();
  12.             bool checkInput = int.TryParse (input, out len);
  13.  
  14.             if (checkInput && len > 0)
  15.             {
  16.                 string output = "";
  17.  
  18.                 for (int i = 2; i <= len; i++) {
  19.                     int num = (i % 2 == 0) ? i : (i * (-1));
  20.                     output += (i != (len)) ? num + ", " : num.ToString ();
  21.                 }
  22.                 Console.WriteLine ("{0}", output);
  23.             }
  24.             else
  25.             {
  26.                 Console.WriteLine ("Please enter a valid length of the sequence! It should be a 32 bit positive Intereger!");
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement