SHARE
TWEET

C# Part I Operators and Expressions Exercise 7

TanyaPetkova Nov 7th, 2013 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. class PrimeNumber
  4. {
  5.     static void Main()
  6.     {
  7.  
  8.         int number = 0;
  9.         while (number < 1 || number > 100)
  10.         {
  11.             Console.Write("Enter a positive integer number <= 100:");
  12.             number = int.Parse(Console.ReadLine());
  13.         }
  14.         for (int num = 1; num <= number; num++)
  15.         {
  16.             if (number % num == 0 && num != 1 && num != number)
  17.             {
  18.                 Console.WriteLine("The number {0} is not prime.", number);
  19.                 break;
  20.             }
  21.             else if (number / num == 1)
  22.             {
  23.                 Console.WriteLine("The number {0} is prime.", number);
  24.                 break;
  25.             }
  26.  
  27.         }
  28.     }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top