WAP to input whether number is prime or not
Answers
Answered by
1
class Prime
{
public static void main(int n)
{
int i,m=0,flag=0;
m=n/2;
if(n==0||n==1)
{
System.out.println(n+" is not prime number");
}
else
{
for(i=2;i<=m;i++)
{
if(n%i==0)
{
System.out.println(n+" is not prime number");
flag=1;
break;
}
}
if(flag==0) { System.out.println(n+" is prime number");
}
}
}
}
{
public static void main(int n)
{
int i,m=0,flag=0;
m=n/2;
if(n==0||n==1)
{
System.out.println(n+" is not prime number");
}
else
{
for(i=2;i<=m;i++)
{
if(n%i==0)
{
System.out.println(n+" is not prime number");
flag=1;
break;
}
}
if(flag==0) { System.out.println(n+" is prime number");
}
}
}
}
Answered by
0
Answer:
Hey! Here is your answer in python...
x = int(input("Enter a number: "))
for i in range(2, x):
if x%i == 0:
print(x, "is not a prime number..")
break
else:
print(x, "is a prime number..")
break
# HOPE THIS HELPS!!
Similar questions