Programming Exercises: Looping

 These are some basic programming exercises that involve loops. Different questions may need different looping type requirements and it is recommended that you should test it on different loops if it is even possible or to identify which type of loop will be the most appropriate in every question.
  1. Write a program that shows the sum of 1 to n for every n from 1 to 50. That is, the program prints 1, 3 (the sum of 1 and 2), 6 (the sum of 1, 2, and 3), and so on.
  2. Write a program that prints every perfect number from 1 through 1000. A number is perfect if it equals the sum of all the numbers that divide evenly into it. For example, 6 is perfect because 1, 2, and 3 divide evenly into it and their sum is 6. 
  3.  Write a program named Investment that calculates the amount of money earned on an investment that includes 12 percent interest. Prompt the user to choose the investment amount from one menu and the number of years for the investment from a second menu. Display the total amount (balance) for each year of the investment. Use a loop instruction to calculate the balance for each year. Use the formula amount = investment * (1 + interest) raised to a power equal to the year to calculate the balance
  4. Write a program that creates a quiz that contains questions about a hobby, popular music, astronomy, or any other personal interest. After the user selects a topic, display a series of questions. The user should answer the questions with one character for multiple choice, true/false, or yes/no. if the user responds to a question incorrectly, display an appropriate response and the correct answer. At the end of the quiz, display the number of correct answers.
  5. Write a program that display a series of survey questions, which one- character answers. At the end of the survey, ask the user if he or she wants to enter another set of responses. If the user responds no. then display the results of the survey for each question. Enter several sets of responses to test the program.
  6. Write a program that prints every integer value from 1 to 20 along with its squared value.

Sharing is caring!