challenge to convert C code to python (prime numbers)
Posted: 27 Nov 2018, 20:54
Hello, a small challenge to convert the following code to python numworks, ti83, hpprime, ...
- Code: Select all
#include <stdio.h>
int isPrime(int n);
int main()
{
int n, cont, i;
printf("How many consecutive primes you want to see? ");
scanf("%d",&n);
cont=1;
i=2;
while( cont<=n )
{
if( isPrime(i) )
{
printf("%d\n",i);
cont = cont+1;
}
i = i+1;
}
return 0;
}
int isPrime(int n)
{
int test_prime=1;
for( int i=2; i<n && test_prime==1; i++ ){
if( n%i==0 )
{
test_prime = 0;
}
}
return test_prime;
}