Advertisement
ntodorova

02_Numbers1toNDivisible

Nov 11th, 2012
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.51 KB | None | 0 0
  1. using System;
  2.  
  3. /*
  4.  * 2. Write a program that prints all the numbers from 1 to N,
  5.  * that are not divisible by 3 and 7 at the same time.
  6.  */
  7. class Numbers1toNDivisible
  8. {
  9.     static void Main()
  10.     {
  11.         int n;
  12.  
  13.         Console.Write("Please enter N: ");
  14.         string str = Console.ReadLine();
  15.  
  16.         if (!int.TryParse(str, out n))
  17.         {
  18.             Console.WriteLine("Invalid number: {0}", str);
  19.         }
  20.         else
  21.         {
  22.             for (int i = 1; i <= n; i++)
  23.             {
  24.                 if (i % (3 * 7) != 0)
  25.                 {
  26.                     Console.WriteLine(i);
  27.                 }
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement