Need an extra challenge when programming in class? Try these!

1) Write a boolean-valued fuction “LeapYear” with a single integer parameter “Year”. The function should return “true” if and only if “Year” is a leap year.

Hint: How to Calculate a Leap Year

Start off using the year you want to calculate.See if it is evenly divisible by 4 (a whole number with no remainder). If it is not, like 1997, it is not a leap year. … See if the year is divisible by 100. If a year is divisible by 4, but not 100, like 2012, it is a leap year. … See if the year is divisible by 400.2) Write a program that uses the function “LeapYear” that lets the user enter a year and reports if it is a leap year.

3) Write a program that asks the user for a number and then outputs all prime numbers less than that number. (Look up “Seive of Eratosthenes” for help with an algorithm.)

4) Create a program that simulates the rolling of two six-sided dice and calculates the sum of the two face values. Have the user enter how many times the dice will be rolled. Keep track in a List of the total number of times that each possible sum was observed. Specifically, create a List called “Sums” and in position 1, count all the times there is a sum of 1 (this should be zero); in position 2, count all of the times the sum is 2; in position 3, count all of the times the sum is 3, etc.

Source:: Mme Sarah’s Blog

## No Comments on "Bonus Computer Program Challenges"