Advertisement
AvengersAssemble

Prime using While

Sep 4th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication14
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int primeInQuestion = int.Parse(Console.ReadLine());
  14.             int i = primeInQuestion - 1;
  15.             while (primeInQuestion%i != 0 && i>1 && primeInQuestion != 2 && primeInQuestion !=3)
  16.             {
  17.                 i--;
  18.                 if (i < 3 && primeInQuestion % i != 0  )
  19.                     Console.WriteLine(primeInQuestion + " is prime.");
  20.             }
  21.             if(primeInQuestion == 2 || primeInQuestion == 3)
  22.                 Console.WriteLine(primeInQuestion + " is prime.");
  23.             if (i>1 && primeInQuestion%i ==0 && primeInQuestion > 3)
  24.                 Console.WriteLine(primeInQuestion + " isn't prime.");
  25.         }
  26.     }
  27. }
  28.  
  29. /* Fibonacci:
  30. using System;
  31. using System.Collections.Generic;
  32. using System.Linq;
  33. using System.Text;
  34. using System.Threading.Tasks;
  35.  
  36. namespace ConsoleApplication14
  37. {
  38.     class Program
  39.     {
  40.         static void Main(string[] args)
  41.         {
  42.             int a1 = 0;
  43.             int a2 = 1;
  44.             Console.Write("Amount of numbers you'd like to be calculated: ");
  45.             int amount = int.Parse(Console.ReadLine());
  46.             Console.WriteLine(a1 + "\n" + a2);
  47.             int i = 0;
  48.             while (i < (amount-2))
  49.             {
  50.                 i++;
  51.                 int a3 = a1 + a2;
  52.                 Console.WriteLine(a3);
  53.                 a1 = a2;
  54.                 a2 = a3;
  55.             }
  56.         }
  57.     }
  58. }
  59. */
  60.  
  61. /* Triangle:
  62. using System;
  63. using System.Collections.Generic;
  64. using System.Linq;
  65. using System.Text;
  66. using System.Threading.Tasks;
  67.  
  68. namespace ConsoleApplication14
  69. {
  70.     class Program
  71.     {
  72.         static void Main(string[] args)
  73.         {
  74.             Console.WriteLine("Enter lenght:");
  75.             int lenght = int.Parse(Console.ReadLine());
  76.             int i = 0;
  77.             while (i < lenght)
  78.             {
  79.                 i++;
  80.                 int b = i;
  81.                 while (b > 0)
  82.                 {
  83.                     b--;
  84.                     Console.Write("*");
  85.                 }
  86.                 Console.WriteLine();
  87.             }
  88.         }
  89.     }
  90. }
  91.  
  92. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement