We will write a program here in which we will check that a given number is a prime number or not.
Prime numbers:
If the natural number is greater than 1 and having no positive divisors other than 1 and the number itself etc.
For example: 3, 7, 11 etc are prime numbers.
Composite number:
Other natural numbers that are not prime numbers are called composite numbers.
For example: 4, 6, 9 etc. are composite numbers.
Output:
Explanation:
We have used nested if else condition to check if the number is a prime number or not.
First, we have checked if the given number is greater than 1 or not. If it is not greater than 1, then the number will directly come to the else part and print 'not a prime number.'
Now, the number will enter into for loop where we perform Iteration from 2 to number/2. Then, we used nested if else condition inside the for loop. If the number is completely divisible by 'i' then, it is not a prime number; else, the number is a prime number.
need an explanation for this answer? contact us directly to get an explanation for this answer