Computer Science, asked by rastogianubhuti911, 3 months ago

write a program to input a no. and display it is prime no. or not.

Answers

Answered by Anonymous
0

Program to Check Prime Number

Program to Check Prime NumberEnter a positive integer: 29 29 is a prime number. In the program, a for loop is iterated from i = 2 to i < n/2 . ... In this case, flag is set to 1, and the loop is terminated using the break statement. After the loop, if n is a prime number, flag will still be 0.

★ᴘʟᴇᴀsᴇ ᴍᴀʀᴋ ᴀs ʙʀᴀɪɴʟɪᴇsᴛ ᴀɴsᴡᴇʀ ᴀɴᴅ ғᴏʟʟᴏᴡ ᴍᴇ!!

Answered by Anonymous
1

# 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")

Output

407 is not a prime number

11 times 37 is 407

Attachments:
Similar questions