Advertisement
steverobinson

Prime number [C#]

Oct 14th, 2010
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2.  
  3. using System.Collections.Generic;
  4.  
  5. using System.Text;
  6. namespace primeorcomposite
  7. {
  8.    
  9.    
  10.     class prime_or_Composite
  11.     {
  12.         static void Main()
  13.         {
  14.             int a,cont=1;
  15.             bool flag=true;
  16.         get_input:
  17.             flag = true;
  18.             Console.Write("\n\nEnter any number: ");
  19.             a = int.Parse(Console.ReadLine());
  20.  
  21.             for (int i = 2; i < a; i++)
  22.             {
  23.                 if (a % i == 0)
  24.                 {
  25.                     flag = false;
  26.                     break;
  27.                 }
  28.             }
  29.             if (!flag)
  30.             {
  31.                 Console.ForegroundColor = ConsoleColor.Red;
  32.                 Console.Beep(500, 500);
  33.                 Console.WriteLine("\n{0} is not a Prime Number!", a);
  34.             }
  35.             else
  36.             {
  37.                 Console.ForegroundColor = ConsoleColor.Green;
  38.                 Console.Beep(1000, 500);
  39.                 Console.WriteLine("\n{0} is a Prime Number!", a);
  40.             }
  41.             Console.ForegroundColor = ConsoleColor.Gray;
  42.             Console.WriteLine("\nContinue? < 1 or 0 >");
  43.             cont = int.Parse(Console.ReadLine());
  44.             if (cont == 1)
  45.                 goto get_input;
  46.             else
  47.             {
  48.                 Console.WriteLine("Thank You!\nExiting.......");
  49.                 Console.Beep(750, 300) ;
  50.                 Console.Beep(750, 300);
  51.                 Console.Beep(750, 300);
  52.             }
  53.         }
  54.  
  55.     }
  56.  
  57.    
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement