Two fundamental problems:
1. You declare a[5] and j[5], then use values of j==1,2,3,4,5. Should be 0,1,2,3,4.
2. You have declared nprimes[] to be of type double, but try to print its value with a %d format specifier. Use %lf for type double.
In fact, I feel that a[] and nprimes[] should be declared and used as type int, since they are used to indicate quantities that have integer values.
In fact, I feel that everything should be type int, since "prime number" only makes since with integers. Why did you use doubles?
I haven't checked your logic to see if the answers you get are correct. I had to leave something for you to do.
Here are the correct answers for the first four:
The number of primes less than 100 is 25
The number of primes less than 1000 is 168
The number of primes less than 10000 is 1229
The number of primes less than 100000 is 9192
I hope this helps.
Regards,
Dave
|