Computing.Net > Forums > Programming > C programming

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C programming

Reply to Message Icon

Name: Nate
Date: August 15, 2003 at 10:08:34 Pacific
OS: xp home
CPU/Ram: 2400/50
Comment:

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
# include

int 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...



Sponsored Link
Ads by Google

Response Number 1
Name: Gorm
Date: August 15, 2003 at 10:46:57 Pacific
Reply:

This maybe a silly question... Are you including
stdlib.h and stdio.h?

Gorm


0

Response Number 2
Name: Nate
Date: August 15, 2003 at 11:06:42 Pacific
Reply:

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..


0

Response Number 3
Name: Ronin1
Date: August 15, 2003 at 13:16:08 Pacific
Reply:

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;
}


0

Response Number 4
Name: Ronin1
Date: August 15, 2003 at 13:18:14 Pacific
Reply:

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


0

Response Number 5
Name: borelli34
Date: August 15, 2003 at 21:29:57 Pacific
Reply:

btw, where is main() devined to begin with?

borelli34


0

Related Posts

See More



Response Number 6
Name: egkenny
Date: August 15, 2003 at 22:37:49 Pacific
Reply:

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.


0

Response Number 7
Name: Allen
Date: August 16, 2003 at 05:02:52 Pacific
Reply:

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++;

}


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C programming

c++ programming for novell www.computing.net/answers/programming/c-programming-for-novell/2525.html

Bike Trader C program www.computing.net/answers/programming/bike-trader-c-program/6557.html

C++ Programming Website www.computing.net/answers/programming/c-programming-website/4752.html