Advertisement
myname0

практикум 5 II. 4

Sep 18th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 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 практикум5_II
  8. {
  9.     class Program
  10.     {
  11.         static bool PrimeNumber(int n)
  12.         {
  13.             for (int i = 2; n >= i * i; i++)
  14.             {
  15.                 if (n % i == 0)
  16.                 {
  17.                     return false;
  18.                 }
  19.             }
  20.                 return true;
  21.         }
  22.         static void Main(string[] args)
  23.         {
  24.             Console.Write("Enter number: ");
  25.             int n = int.Parse(Console.ReadLine());
  26.          
  27.             for (int i = n - 1; i > 2; i--)
  28.             {
  29.                 if (PrimeNumber(i))
  30.                 {
  31.                     Console.WriteLine("{0}", i);
  32.                     break;
  33.                 }
  34.             }
  35.                 if (n == 1 || n == 2 || n == 3)
  36.                     Console.WriteLine("there is not prime number less then {0}", n);        
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement