Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Problem 2. Numbers Not Divisible by 3 and 7
- //Write a program that enters from the console a positive integer n and prints all the numbers from 1 to n not divisible by 3 and 7, on a single line, separated by a space.
- using System;
- class NumbersNotDivisibleBy3And7
- {
- static void Main()
- {
- Console.Write("Please, enter positive number: ");
- uint number = uint.Parse(Console.ReadLine());
- //Check if number is positive
- if (number > 0)
- {
- //Print numbers from 1 to n.
- for (uint i = 1; i <= number; i++)
- {
- if ((i % 3 == 0) || (i % 7 == 0))
- {
- continue;
- }
- //if i not divisible by 3 and 7 print to Console
- Console.Write(i + " ");
- }
- }
- else
- {
- Console.WriteLine("Please, enter positive integer number!");
- }
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement