I have a long and confusing problem (to me) I'm new to C. I was wondering if anyone could help me with my problem.
File: Prime.h
#include <stdio.h>
#include <stdlib.h>
int is_prime(int n);
File: is_prime.c
#include "primes.h"
int is_prime(int n)
{
int k, limit;
if (n == 2)
return 1;
if (n % 2 == 0)
return 0;
limit = n /2;
for (k = 3; k <= limit; k += 2)
if (n % k == 0)
return 0;
return 1;
}
File: main.c
#include "primes.h"
int main(void)
{
int n, prime, count;
printf("PRIMES WILL BE PRINTED.\n");
printf("\nHow many do you want to see? ");
scanf("%d,&n");
n = 0;
prime = 1;
count += 1;
while(prime < n)
{
if(is_prime(count))
{
prime++;
printf("%d %d\n", prime, count);
}
count++;
}
return 0;
}
I know that there is something definetly wrong with main.c
I've played with the code for about 2 days now and i don't get ANY output.
Can someone please help