Quick Navigation
Elementary Exercises
- Write a program that prints ‘Hello World’ to the screen.
- Write a program that asks the user for their name and greets them with their name.
- Modify the previous program such that only the users Alice and Bob are greeted with their names.
- Write a program that asks the user for a number
n
and prints the sum of the numbers 1 ton
- 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 - 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
. - Write a program that prints a multiplication table for numbers up to 12.
- 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.)
- 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.
- 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