Maths and Number Puzzles

Sums

Write a program that asks the user for a number n and prints the sum of the numbers 1 to n

Products

Write a program that asks the user for a number n and gives him the possibility to choose between computing the sum and computing the product of 1,…,n.

Multiples

Write a program that given a number n produces the times table for that number. Modify the previous program such that only multiples of three and five are considered in the sum, e.g. 3, 5, 9, 15 for n=17

Primes

Write a program that prints all prime numbers.

Triangles

Write a program that calculates the first 20 Triangle Numbers using Gauss’ Equation which says that to calculate the nth triangle number. triangleNumber-300x33 Can you create a visually output?  This could be either ASCII art or via a GUI.  

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.