Advertisement
cortez

Sequence Members

Oct 5th, 2012
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class SequenceDec
  5. {
  6.     private static void Main()
  7.     {
  8.         int n = 0;
  9.         Console.WriteLine("Point out how many members of the sequence you'd like to be displayed below: ");
  10.         string input = Console.ReadLine();
  11.         bool wrongInput = !int.TryParse(input, out n);
  12.         if (wrongInput)
  13.         {
  14.             Console.WriteLine("Sorry pal! Either you cannot differ number from anything else, or you are trying to bug my program :) Well, you can try again later !!!");
  15.         }
  16.         else
  17.         {
  18.             int a = 2;
  19.             while (true)
  20.             {
  21.                 wrongInput = a <= n + 1;
  22.                 if (!wrongInput)
  23.                 {
  24.                     break;
  25.                 }
  26.                 int evenOdd = a % 2;
  27.                 wrongInput = evenOdd == 0;
  28.                 if (wrongInput)
  29.                 {
  30.                     Console.Write(string.Concat(a, ", "));
  31.                 }
  32.                 else
  33.                 {
  34.                     Console.Write(string.Concat(a * -1, ", "));
  35.                 }
  36.                 a++;
  37.             }
  38.             Console.WriteLine();
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement