Write a program to accept a number and check whether the number is prime or not using the function int checkprime (int n).The function returns 1 if the number is a prime otherwise 0.
Answers
Answer:
Input
# Program to check if a number is prime or not
num = 407
# To take input from the user
#num = int(input("Enter a number: "))
# prime numbers are greater than 1
if num > 1:
# check for factors
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")
# if input number is less than
# or equal to 1, it is not prime
else:
print(num,"is not a prime number")
Answer:
enter a positive integer : 23
23 is also a prime number
In the above example te number entered by the user is passed to the check prime number () functions
the function returns true if the number passed to a function is prime number and return false if the number passed is not a prime number
Finally the appropriate message is printed from the main () functions