daily pastebin goal
94%
SHARE
TWEET

Coding Conundrums 1.1: Sequence Reversal

starbeamrainbowlabs Feb 9th, 2015 175 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. class Program
  4. {
  5.         public static void Main(string[] args)
  6.         {
  7.                 if(args.Length != 10)
  8.                 {
  9.                         Console.WriteLine("Coding Conundrums Problem 1.1 Solution: Sequence Reversal");
  10.                         Console.WriteLine("---------------------------------------------------------");
  11.                         Console.WriteLine("Problem Description:");
  12.                         Console.WriteLine("    I want a program that reads in 10 numbers and prints them out");
  13.                         Console.WriteLine("    in the reverse order to the order they were entered.");
  14.                         Console.WriteLine();
  15.                         Console.WriteLine("(You entered {0} numbers)", args.Length);
  16.                         Console.WriteLine();
  17.                         Console.WriteLine("Use it like this: ");
  18.                         Console.WriteLine("    sequencereverse.exe 1 2 3 4 5 6 7 8 9 10");
  19.  
  20.                         return;
  21.                 }
  22.  
  23.                 int[] numbers = new int[args.Length];
  24.                 for(int i = 0; i < args.Length; i++)
  25.                 {
  26.                         if(!int.TryParse(args[i], out numbers[i]))
  27.                         {
  28.                                 Console.WriteLine("Error: {0} is not a number.", args[i]);
  29.                                 return;
  30.                         }
  31.                 }
  32.                 Array.Reverse(numbers);
  33.  
  34.                 for(int j = 0; j < numbers.Length; j++)
  35.                 {
  36.                         Console.Write("{0} ", numbers[j]);
  37.                 }
  38.                 Console.WriteLine();
  39.         }
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top