Prime number
The given number is divisible only for itself and one that is called prime number.
Example-1:
Input : n = 5 Output : Prime number Explain : The 5 is divisible by 5 and 1 only so its "Prime number".
Example-2:
Input : n = 4 Output : Not a Prime number Explain : The 4 is divisible by (1,2,4).So its "Not a Prime number".
Solution
public class Main { public static void main(String [] args) { int n = 5; int i; for (i = 2;i<n;i++) { if(n % i == 0) { System.out.print("Not a prime number"); break; } } if(i==n) { System.out.print("Prime number"); } } }
n = 5 for i in range(2,n): if(n % i == 0): print("Not a prime number") break else: print("Prime number")
Output
Prime number