Make a program in python to check if a number is prime or not using loops
Answers
Answered by
6
Answer:-
N = int(input("Enter the number"))
p = 1
For i in range(2, N) :
if N%i==0 :
p=0
break
if p==1 :
print("The number is a prime number")
else :
print("The number is not a prime number")
——————-————————————————-——
Hope it helps.....
Answered by
1
Program in python :
Explanation:
number=int(input("Enter the number: "))#take a input from the user.
i=2
count=0
while(i<=(number/2)):#while loop which checks the number to be prime or not.
if(number%i==0):
count=1
i=i+1
if(count==0):
print("The number is a prime number")
else:
print("The number is not a prime number")
Output:
- If the user input as 4, then it will prints not a prime number.
- If the user inputs as 2, then it will prints the prime number.
Code Explantion :
- The above code is in python language, which takes the inputs from the user and then runs the while loop up to the number divisible by 2.
- Then checks the number to be divisible by all the value which is less than from that number.
- If no number can divide that number, then it is a prime number.
Learn More:
- Python : https://brainly.in/question/14689905
Similar questions
Math,
5 months ago
Math,
5 months ago
Accountancy,
5 months ago
Physics,
11 months ago
Math,
1 year ago