Advertisement
AnitaN

06.LoopsHomework/02.NumbersNotDivisibleBy3And7

Mar 29th, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. //Problem 2. Numbers Not Divisible by 3 and 7
  2. //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.
  3.  
  4. using System;
  5.  
  6. class NumbersNotDivisibleBy3And7
  7. {
  8.     static void Main()
  9.     {
  10.         Console.Write("Please, enter positive number: ");
  11.         uint number = uint.Parse(Console.ReadLine());
  12.         //Check if number is positive
  13.         if (number > 0)
  14.         {
  15.             //Print numbers from 1 to n.
  16.             for (uint i = 1; i <= number; i++)
  17.             {
  18.                 if ((i % 3 == 0) || (i % 7 == 0))
  19.                 {
  20.                     continue;
  21.                 }
  22.                 //if i not divisible by 3 and 7 print to Console
  23.                 Console.Write(i + " ");
  24.             }
  25.         }
  26.         else
  27.         {
  28.             Console.WriteLine("Please, enter positive integer number!");
  29.         }
  30.         Console.WriteLine();
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement