Skip to content

Instantly share code, notes, and snippets.

@Brianceasar
Last active November 30, 2022 06:29
Show Gist options
  • Save Brianceasar/de37b4dfe01593d6c3af6a1d76fb7e80 to your computer and use it in GitHub Desktop.
Save Brianceasar/de37b4dfe01593d6c3af6a1d76fb7e80 to your computer and use it in GitHub Desktop.
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.
namespace PrintNNumbers
{
class Program
{
static void Main (string[] args)
{
int n;
Console.Write("Enter the first number n: ");
bool isInt = int.TryParse(Console.ReadLine(), out n);
if (isInt)
{
for (int i = 1; i <= n; i++)
{
Console.WriteLine(i);
}
}
else
{
Console.WriteLine("Not a valid entry! n is not an integer!");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment