Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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.
- class Numbers1N
- {
- static void Main()
- {
- Console.Write("Enter n: ");
- string a = Console.ReadLine();
- int n = int.Parse(a);
- if (n > 0)
- {
- for (int i = 1; i <= n; i++)
- {
- Console.WriteLine(i);
- }
- }
- else if (n < 0)
- {
- for (int i = -1; i >= n; i--)
- {
- Console.WriteLine(i);
- }
- }
- else
- {
- Console.WriteLine("There is only one" );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment