Cpe 150 Laboratory 4: Control Structures Ii: 1 Objectives
Cpe 150 Laboratory 4: Control Structures Ii: 1 Objectives
1 Objectives
• To understand basic problem-solving techinques.
• To be able to develop algorithms through the process of top-down stepwise refinment.
• To be able to use the while and for repetition structures to execute statementin a program repeatdly.
• To understand counter-controlled repetition and sentinel-controlled repetition.
• To be able use the increment, decrement, assignment and logical operators.
• To be able to use break and continue program control statements.
1
New Balance: 5894.78
Credit Limit Exceeded.
*************************************
Why it is necessary to ask the user to input the first account number before you begin the while loop?
What problems could occur if the user was asked for an account number only inside the while loop?
2
You are given an integer number n. Tanya will subtract one from it k times. Your task is to print the
result after all k subtractions. It is guaranteed that the result will be positive integer number.
Input
The first line of the input contains two integer numbers n and k(2 ≤ n ≤ 109 , 1 ≤ k ≤ 50) — the number
from which Tanya will subtract and the number of subtractions correspondingly.
Output
Print one integer number — the result of the decreasing n by one k times.
n: 512
k: 4
50
n: 1000000000
k: 9
1
5 Postlab Exercise
Write a program that reads a nonnegative integer and computes and prints its factorial. The factorial of
a nonnegative integer n is written n! (pronounced “n factorial”) and i defined as follows: