Question: Task 2 Basic Programming: On repl.it, program a basic prime number generator. For taking input, take a look at the scanf function, which operates similarly

Task 2 Basic Programming:

  1. On repl.it, program a basic prime number generator. For taking input, take a look at the scanf function, which operates similarly to the printf function:

    1. http://www.cplusplus.com/reference/cstdio/scanf/

    2. You will note that when passing the variables that you want to store the results in, that you have to precede them with an ampersand (&). The reason for this is because you need a reference for the variable, rather than passing it straight in, and the ampersand gets a reference for a variable called a pointer. Unlike Java, memory in C is not managed, and as a result, you are able to create variables which are pointers to other variables, sort of like how reference variables work in Java. Take a look at the following example (copy and paste it into repl it if you want to run it) for a bit of an explanation, but you do not really need to know this well, just enough to be able to use scanf: pointer_example.c

  2. Your code should prompt for an integer (which will be greater than or equal to 2), and print out all of the prime numbers smaller than the number input. You may print these out however you want, but it would be better if you would print them out space separated, or on separate lines.

    1. You do not need to create a function for this Task

    2. Basic pseudocode that you can use is:

N = input()

for i in 2, 3, , N

is_prime = true

for j in 2, 3, , i

if i % j == 0

is_prime = false

if is_prime

print(i)

  1. Copy this code into notepad++ or something similar, and save it to your local machine

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!