You are on page 1of 1

CSCI 201 Assignment 4 Due Date Submit in D2L before 10am on February 28th.

You may take an extra 24 hours for a 10-point penalty. No assignments will be accepted after 10am on March 1st. Work Alone It is important that all work you submit for this assignment (and all assignments in this class) be your own. You may talk to other students about the assignment, but you may not exchange code. All code written for this assignment must originate from your brain and your fingertips. You may not copy code from any other source (including the Internet). Please see me if you have questions! Coding Standards Be sure to follow the class coding standards (available in D2L) for this assignment. Part 1 Write a program that prints out the sum of the first n integers and allows the user to supply the number n. Ask the user how many numbers he/she wants summed. The number n should be a positive integer. For example, if the user enters 5, you will calculate 1 + 2 + 3 + 4 + 5, and you will tell the user that the sum is 15. If the user enters a negative integer or 0, reprompt him/her to enter a positive integer until he/she does so. Part 2 Write a program that determines the factors of a number the user enters. Prompt the user to enter a positive integer. Print a list of all the factors of that integer. A factor is a number that divides the original number evenly. For example, the factors of 16 are: 1, 2, 4, 8, 16. Every integer has at least two factors: 1 and the number itself. Hint: the mod (remainder) operator will help you determine if a number divides another evenly. If the user enters a negative integer or 0, reprompt him/her to enter a positive integer until he/she does so. Part 3 Write a program that prints out a hollow square made of asterisks (*). Ask the user how big of a square he/she wants. The size should be a positive integer. If the user enters a negative integer or 0, reprompt him/her to enter a positive integer until he/she does so. Put a space after each asterisk to make the shape more square-like. Here are some sample squares: * * * * * * * * * * * * * * * * * * * * * * * * * Size 1 Size 2

Size 3

Size 4

You might also like