Write a program in C# that enters from the console a positive integer n and prints all the numbers from 1 to n not divisible by 3 and 7
The following program answers the following question : How many integers from 1 to Entered value are not divisible by 3, 7
Ex: (Entered value may be 10, 50, 100, 1000 or any number to 2,147,483,647)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
static void Main(string[] args) { Console.WriteLine("Enter an integer:"); int n = int.Parse(Console.ReadLine()); for (int i = 1; i <= n; i++) { if (i % 3 != 0 && i % 7 != 0) { Console.Write("{0} ", i); } } Console.ReadKey(); } |
Output:
You can find more similar examples of programming for this programming language in the site.
Write a program in C# print all the numbers from 1 to 100 not divisible by 3 and 7
1 2 3 4 5 6 7 8 9 10 11 12 13 |
static void Main(string[] args) { for (int i = 1; i <= 100; i++) { if (i % 3 != 0 && i % 7 != 0) { Console.Write("{0} ", i); } } Console.ReadKey(); } |