Sale!

CS211 Homework 1 Solved

Original price was: $40.00.Current price is: $35.00.

Category:

Description

5/5 - (1 vote)

The aim of this homework assignment is to write simple programs that will be a review of the old material from previous course. It consists of writing 4 simple programs.

  1. A prime number is a number other than 1 that is divisible only by 1 and itself. (Example of prime numbers: 2, 3, 5, 7, …). Write a program that asks the user for a positive integer. The program will print out all prime numbers from 1 to that positive integer. It is better if you write a separate function to check out if an integer is prime or not.
  2. A perfect number is such a number where all of its proper divisors add up to the number itself. (Examples of perfect numbers: 6 is a perfect number. Proper divisors of 6 are 1, 2, and 3. 1 + 2 + 3=6. 28 is a perfect number. Proper divisors of 28 are 1, 2, 4, 7, 14. 1 + 2 + 4 + 7 + 14 = 28.) Write a program that asks the user for a positive integer. The program will print all perfect numbers from 1 to that positive integer. It is better if you write a separate function to check out perfectness of an integer.
  3. Def: A year is a century year if it is divisible by 100. (Ex. 100, 200, 300,…)
    Def: A year is non-century year if it is not a century year. (Ex. 1, 2, 3, 4, …)
    Def: A year is a leap year if it is a non-century year that is divisible by 4, or a century year that is divisible by 400. Nothing else is a leap year.

    Write a program that is going to ask the user for the range of years and print out all leap years in that range 5 to a line. It is better if you write a separate function to check if the given year is a leap year or not.

  4. Write a program that will continuously ask the user for positive integers (until the user enters a negative integer at which the program will be terminated). Every time the user inputs a positive integer the program will print out this integer in reverse. Your program should have a function that accepts and integer and returns an integer in reverse. To convert the integer to its reverse, your program will call this function.

Please submit this homework to your lab instructor following lab instructor’s instructions.