Check if number is prime
![Question: Write a code to check whether a number is prime or not. Condition use
function check0 to find whether entered no is positive or negative, if negative then
enter the no, And if yes pas no as a parameter to prime() and check whether no is
prime or not?
. Whether the number is positive or not, if it is negative then print the message
"please enter the positive number"
It is positive then call the function prime and check whether the take positive
number is prime or not.
C Code:
#include <stdio.h>
void prime(int n)
{](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2bb17e7e-2ebe-4c45-b40e-6cf48e363ffb%2F8db44568-4750-43a9-8e9e-d32af29bc809%2Fcxnojdf_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
This is very simple.
I have written a simple Python code to solve the problem. I have also attached the output in Step 2.
----------------------------------------------- Python Code -------------------------------------------------
def prime(n):
if n > 1:
for i in range(2, n):
if (n % i) == 0:
print(n,"is not a prime number ")
break
else:
print(n,"is a prime number ")
return
def check(n):
if n < 0:
print(" Please enter a positive number ")
n = int(input(" Now enter a positive number (NOT 0) : "))
prime(n)
else:
prime(n)
if __name__ = "__main__":
N = int(input(" Enter a number : "))
print(check(N))
Step by step
Solved in 2 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
![Programming with Microsoft Visual Basic 2017](https://www.bartleby.com/isbn_cover_images/9781337102124/9781337102124_smallCoverImage.gif)