CM151: Lab 7 -- Decisions.


Lab Goal:

Develop some programs using conditionals.


Assignments:

  • A person is eligible to be a US senator if they are at least 30 years old and have been a US citizen for at least 9 years. To be a US representative these numbers are 25 and 7, respectively.

    Write a program that asks for the users age and years of citizenship as inputs and then outputs their eligibility for the Senate and House of representatives.


  • A year is a leap year if it is divisible by 4, unless it is a century year that is not divisible by 400. (1800 and 1900 are not leap years while 1600 and 2000 are.)

    Write a program that asks the user for a year and then tells the user whether or not the year is a leap year.


  • The Goldbach conjecture asserts that every even number is the sum of two prime numbers.

    Write a program that gets a number from the user. Check to make sure that it is even. If the number is at least 2 and less than 100, output what two prime numbers add up to that number.


  • Optional program (nothing to submit): Write a program that calculates all prime numbers less then 100 and output them to the screen.


Submission

Once you have finished your three programs, submit them via Moodle.