Final answer:
To write a program that prints all prime numbers up to a given integer, use a loop to iterate through each number and check if it is prime by dividing it by all numbers from 2 up to its square root.
Step-by-step explanation:
To write a program that prints all prime numbers up to a given integer, you can use a loop to iterate through each number from 2 up to the given integer. For each number, you can check if it is prime by dividing it by all numbers from 2 up to its square root. If the number is divisible by any of these numbers, it is not prime and you can move on to the next. Otherwise, it is prime and you can print it.
Here's an example implementation in Python:
def is_prime(num):
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
n = int(input('Enter an integer: '))
for i in range(2, n + 1):
if is_prime(i):
print(i)
In this example, the is_prime() function checks if a number is prime, and the main program prompts the user for an integer and prints all prime numbers up to that integer.