Saturday, 17 November 2018

LAB ACTIVITY 7 : Repetition Structure


Exercise 

a)  Create a program to generate a multiplication table by using while loop. The multiply is determined based on user input. Your output should be like below:

     Output:
     Please enter multiplication table: 3

     3 Times Table

     1 * 3 = 3
     2 * 3 = 6
     ..
     ..
     12 * 3 = 36




b)   Calculate the total of any five numbers using do … while loop.Your output should be like below:

      Output:
      Please enter number 1: 2
      Please enter number 2:  3
      Please enter number 3:  1
      Please enter number 4:  4
      Please enter number 5:  5

      The total of five numbers is 15




c)   Write a program for the following problem by using for statement:
Ahmad saves RM1000 in his account in a bank which returns 5% of annual interest. Assuming that all interests is left deposited in his account, calculate and print the amount of money in his account at the end of each year for 10 years by using for loop.









No comments:

Post a Comment