Advertisement
Guest User

NotDivisible

a guest
Mar 25th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System;
  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,
  3. //on a single line, separated by a space.
  4. class NotDivisible
  5. {
  6.     static void Main()
  7.     {
  8.         Console.Write("Please enter a number: ");
  9.         int n = int.Parse(Console.ReadLine());
  10.         bool notDivisible = n % 3 != 0 && n % 7 != 0;
  11.         for(int i = 1;i<=n;i++)
  12.         {
  13.             if(i % 3 != 0 && i % 7 != 0)
  14.             {
  15.                 Console.Write(i);
  16.                 if(i<n)
  17.                 {
  18.                     Console.Write(" ");
  19.                 }
  20.             }
  21.         }
  22.         Console.WriteLine();
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement