Professional Documents
Culture Documents
Introduction To C/C++ Course: IT116IU International University - VNU HCM Date: 13 Sep. 2021 Dr. Ly Tu Nga Time: 4 Hours
Introduction To C/C++ Course: IT116IU International University - VNU HCM Date: 13 Sep. 2021 Dr. Ly Tu Nga Time: 4 Hours
1. Write a program that inputs an n-digit number then output its n digits from least to most
significant (reverse):
Input: 132768
Output: 8 6 7 2 3 1
Algorithms
// initialize n ,r
//input n =25
//while n >0
//r = n % 10 , r = 5 , r = 2
//n = n/10, n = 2 , n =0
//print r, 5 2
Result:
Introduction to C/C++ Course: IT116IU
International University – VNU HCM Date: 13 Sep. 2021
Dr. Ly Tu Nga Time: 4 hours
Please collect your bugs in here and write down the solution to fix them.
2. Write a program to input integers, the program ends when user input 0. Print the
minimum (different from 0) and maximum number (different from 0) among the input
numbers:
Input: -3 5 -2 9 8 10 5 -1 0
Min: -3
Max: 10
Algorithm:
initalize n,min,max
input the first n
print n
assign max=n
min=n
input n
print n
while n is not equal to 0
if max < n then max=n
if min > n then min=n
input n
end while
print max and min
Please collect your bugs in here and write down the solution to fix them.
When typing decimal numbers program will print indefined
So use “float” to fix them
Result:
Introduction to C/C++ Course: IT116IU
International University – VNU HCM Date: 13 Sep. 2021
Dr. Ly Tu Nga Time: 4 hours
3. Given number x and y. Using only plus, minus, multiply and divide to evaluate the
following equation using no more than 16 operations:
3x2y2 – 2xy2 – 7x2y – 4y2 + 15xy + 2x2 – 3x +10y + 6
Algorithm
Bugs:
Result:
4. Write a Taxi meter program to calculate the taxi fare for a given mileage.
Result: