Hey guys. I'm new to the forums and C, but I think I'm learning quickly. I think I got the basic program down but I need to fine tune it for this next step.
For my main function I need to call isprime from 1 to 1000 using a for loop. If the call isprime(n) returns a 1, I need to print that number. After I've done this, I need to seperate them into columns after every tenth number. This I can't figure out.
Here's my code so far. Any hints would be appreciated. Thanks!
Code:
#include "stdafx.h"
int isprime(int n);
int _tmain(int argc, _TCHAR* argv[])
{
int x, col = 0;
for ( x = 1; x <= 1001; x++)
{
if( isprime(x) == 1)
printf("%d ", x);
}
}
int isprime(int n)
{
int div;
if(n == 2)
return 1;
for(div = 2; div < n; div++)
{
if(n % div == 0)
return 0;
}
return 1;
}