0
what a program prime numbers between 2 to 100?
i am trying to get this one but the output numbers(9.15.21.25...)are incorrect these are not prime number plz give me a help or a hint https://code.sololearn.com/cb7hAGO16yn2/?ref=app
5 Answers
0
NinjaGamer ,
How should one use that? It returns True, False, or an integer.
Testing it with this call,
for n in range(12):
print(n, p(n))
produces this output.
0 False
1 True
2 False
3 3
4 False
5 True
6 False
7 True
8 False
9 3
10 False
11 True
Does that mean it thinks 1 is prime and 2 isn't? What should the caller do when it returns 3?
+ 4
#include <stdio.h>
int main()
{
int x,y,z;
for(x=3;x<100;x++)
{
z = 0;
for(y=2;y<x;y++)
{
if(x%y==0)
{
z = 1;
break;
}
}
if (z == 0)
printf("prime num are: %d\n",x);
}
return 0 ;
}
https://code.sololearn.com/c2ZUWzXz55vg/?ref=app
+ 3
This is a very efficient Python function.
import math
def p(n):
i = 1
if n % 2 == 0:
return False
while i < math.sqrt(n):
i+=2
if n % i == 0:
return i
return True
+ 2
A͢J thank you so much â¤
0
NinjaGamer thank you brođ§Ą