Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- ////Write an expression that checks if given positive integer number n (n ≤ 100) is prime (i.e. it is divisible without remainder only to itself and 1).
- class PrimeNumebrCheck
- {
- static void Main()
- {
- Console.Write("Enter a positive number, smaller or equal to 100: ");
- int n = int.Parse(Console.ReadLine());
- bool isPrime = false;
- if ((n>1) && (n<=100))
- {
- for (int i = 2; i <=n; i++)
- {
- if (n%i==0)
- {
- isPrime = true;
- }
- }
- Console.WriteLine(isPrime);
- }
- else
- {
- Console.WriteLine("False");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement