Computer Science, asked by yeshukiraah, 5 months ago

Write a program that prompts to enter a number and check whether the number is (i) prime or not

Answers

Answered by ankitdwivediii
0

Answer:

#include <stdio.h> int main() { int n, i, flag = 0; printf("Enter a positive integer: "); scanf("%d", &n); for (i = 2; i <= n / 2; ++i) { // condition for non-prime if (n % i == 0) { flag = 1; break; } } if (n == 1) { printf("1 is neither prime nor composite."); } else { if (flag == 0) printf("%d is a prime number.", n); else printf("%d is not a prime number.", n); } return 0; }

Output

Enter a positive integer: 29 29 is a prime number.

Answered by Anonymous
1

Answer:

hello,

its using python

Explanation:

# program to enter a number and check whether its prime or not

n=int(input("enter the number"))

if n==2:

   print(" 2 is a prime number")

else:

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

______________________

hope it helps you

please mark brainliest

@ItzSnowySecret07

Similar questions