• You are here:
• Home »

# programming exercises

## Elementary Exercises

1. Write a program that prints ‘Hello World’ to the screen.
2. Write a program that asks the user for their name and greets them with their name.
3. Modify the previous program such that only the users Alice and Bob are greeted with their names.
4. Write a program that asks the user for a number `n` and prints the sum of the numbers 1 to `n`
5. Modify the previous program such that only multiples of three or five are considered in the sum, e.g. 3, 5, 6, 9, 10, 12, 15 for `n`=17
6. Write a program that asks the user for a number `n` and gives them the possibility to choose between computing the sum and computing the product of 1,…,`n`.
7. Write a program that prints a multiplication table for numbers up to 12.
8. Write a program that prints all prime numbers. (Note: if your programming language does not support arbitrary size numbers, printing all primes up to the largest number you can easily represent is fine too.)
9. Write a guessing game where the user has to guess a secret number. After every guess the program tells the user whether their number was too large or too small. At the end the number of tries needed should be printed. I counts only as one try if they input the same number multiple times consecutively.
10. Write a program that prints the next 20 leap years.

## Moderate to Difficult

Programming Exercises for 2-Dimensional Arrays

Problem 1:  Image Display Program

Write a program to read in an image encoded in a 30 x 30 integer array, convert it to a character array by replacing 0's with spaces and 1's with periods (.), and write the resulting array to an output file.

Input file:  Img9-1.txt

Problem:  Image Inversion

Revise program from problem 1 invert an image around the Col = Row axis.

Input file:  Img9-2.txt