Programming Fundamental
Programming Fundamental
Learning Objectives: The objective of this exercise is to get you to write, compile and run a
number of simple programs in C++ which make use of basic decision constructs and for loops.
OBS:
For each exercise you need to write the flowchart on your register before translating
it to your C++ program.
C++ Source Code with proper comments.
At the top of your C++ source code also write the following comments
/* This programme is prepared by XXXXXXXXXXX on dd/mm/yyyy. This programme
……….(a bit of explanation what your programme does.*/.
Output: 0
1
2
3
4
Exercise 1: Print the following series using for loop and while loop
Exercise 3: Write a program that reads ten numbers using while loop and determines and prints
whether it is odd or even. (Hint: use the modulus operator. Any even number is multiple of two,
and any multiple of two gives a remainder of zero when divided by two.)
Exercise 4: Write a program which asks the user to enter 10 numbers using loops and prints out
the message “even” if the number is even and “divisible by three” if the number is divisible by
three.
Exercise 5: A person invests $1000.0 in a savings account yielding 5% interest. Assuming that all
interest is left on deposit in the account, calculate and print the amount of money in he account at
the end of each year for 10 years. Use the following formula for determining these amounts:
a = p(1+r)n
where
p is the original investment(i.e. the principal)
r is the annual interest rate
n is the number of years
a is the amount on deposit at the end of the nth year.
Sample output