Write a program that will prompt a user to enter an integer between 2 and 999, inclusive.

As output, the program will display all prime integers between 2 and the user-input value.

This program will use a process of “cancellation to identify the required prime values. To do so, the program will do the following:
1) store the integers 0, 0, 2, 3, 4, . . ., 997, 998, 999 (note: 0 and 1 will not be considered);
2) prompt the user for an integer between 2 and 999, inclusive;
3) using 2 (the first prime integer), the program will proceed to cancel all multiples of 2 found in the remaining set by setting each multiple to 0;
4) the program will then move to the next non-zero integer (which will be the next prime, since it was not cancelled by the process in #3 above) and repeat the process in #3 above, but now using this new value;
5) the program will continue this process of cancellation until the user-input value is reached.

As output, the program will display all prime values between 2 and the user-input value.

i don't understand how to do this.

Recommended Answers

All 2 Replies

The description is quite exhaustive. I suggest you read it and try yourself while waiting for someone to write your code for you so you can in the last 5 minutes before your homework is due slap something together which has a passing chance of coming near to working because noone is going to write your code for you.

Why don't kids today even TRY to do their own assignments?

>i don't understand how to do this.
You should have paid attention in class then.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.