7
17/10/2024 7:54 am
Topic starter
How to make console application which will take input a number and it will write 5 earlier numbers on console if user type 7 then output should be 6,5,4,3,2 or if user type 2 then output should be 1,0,-1,-2,-3.---------- sorry i am totally new in programming.
2 Answers
7
17/10/2024 7:58 am
You should use the reverse for loop;
Try this code for your task:
using System; class NumbersFromNToOne { static void Main() { Console.WriteLine("Please write your number: "); int n = int.Parse(Console.ReadLine()); for (int i = n-1; i >= n-5; i--) { Console.Write("{0} ",i); } Console.WriteLine(); } }
Thank you so much sir _/\_
7
17/10/2024 8:40 am
The first i MUST BE n-1 and the whole reverse for loop will look like this:
for (int i = n-1; i >= n-5; i--) { Console.Write("{0} ",i); }