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

20th Nov 2023, 3:28 PM
zay yar
zay yar - avatar
5 Réponses
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?
28th Nov 2023, 5:06 PM
Rain
Rain - avatar
+ 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
20th Nov 2023, 3:47 PM
A͢J
A͢J - avatar
+ 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
21st Nov 2023, 2:38 AM
NinjaGamer
NinjaGamer - avatar
+ 2
A͢J thank you so much ❤
20th Nov 2023, 4:17 PM
zay yar
zay yar - avatar
0
NinjaGamer thank you bro🧡
21st Nov 2023, 1:16 PM
zay yar
zay yar - avatar