pupesko

SoftUni - 4.8* Numbers from 1 to n

Oct 1st, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. //Write a program that reads an integer number n from the console and prints all the numbers in the interval [1..n], each on a single line. Note that you may need to use a for-loop.
  2.  
  3. class Numbers1N
  4. {
  5.     static void Main()
  6.     {
  7.         Console.Write("Enter n: ");
  8.         string a = Console.ReadLine();
  9.         int n = int.Parse(a);
  10.  
  11.         if (n > 0)
  12.         {
  13.             for (int i = 1;  i <= n; i++)
  14.             {
  15.              Console.WriteLine(i);
  16.              }
  17.         }
  18.         else if (n < 0)
  19.         {
  20.             for (int i = -1; i >= n; i--)
  21.             {
  22.                 Console.WriteLine(i);
  23.             }
  24.         }
  25.         else
  26.         {
  27.                 Console.WriteLine("There is only one" );
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment