Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Having problems with a program. I am suppose to write a program that prints out n prime numbers, whatever is inputed.
I have to use a file 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
# includeint is_prime(int n);
My part to call this function is:
# include "primes.h"void prn_title(void);
void prn_headings(void);
void read_and_prn_data(int n);int n;
int main(void)
{
printf("This program will compute the first 'n' primes \n",
"How many primes would you like to see?");
scanf("%d", &n);
prn_title();
prn_headings();
read_and_prn_data(n);printf("Thankyou... Goodbye...");
return 0;
}void prn_title(void)
{
printf("\n%s%s%s\n",
,
" Primes Will Be Printed. \n",
);
}void prn_headings(void)
{
printf("%5s%12s\n\n",
"Count", "p");
}void read_and_prn_data(n)
{
int count = 1, p = 0; /*p = prime #*/for (count = 1; count = n; ++count)
{
is_prime(p);
printf("%5d%12d\n",count, p);
++count;
}
}I get a compiler error "unresolved externals" when I try to run the program. It compiles but just won't run so I can't even see if it runs properly.
Any help on this would be much appreciated.
thankyou...

I just checked... I have both of the .h's in my .h file. I have found alot of people on the net with the same problem lol... Unfortunately there are no answers I could find to remedy the problem... Thanks for any other help you can give..

Put the function prototypes in main, put the function definitions and/or defines in a seperate c file.
#include
#include
#include "primes.c"void prn_title(void);
void prn_headings(void);
void read_and_prn_data(int n);int main(void)
{
return 0;
}

Geezz... been so long since my last visit here that I'd forgotten this board strips html markers. :P

It would also help if you used the "Click Here" on the Confirm Post Message page. This will allow you to post your code with all the formatting intact.

try this loop
ctr = 0;
temp =2;
while (ctr = input_number)
{ nmultiples = 0;
for (i=2; itemp; i++)
{ if (temp % 2 == 0)
nmultiples++;
}if (nmultiples != 0)
printf("%d\n",temp);temp++;
}

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |