You are on page 1of 4

Introduction to C/C++ Course: IT116IU

International University – VNU HCM Date: 13 Sep. 2021


Dr. Ly Tu Nga Time: 4 hours
C/C++ Programming
Lab 01: Intro. to Visual Studio Code
Objective:
-how to install/use Visual studio code
-use if…else…, while,
-fix bugs.
Materials:
-Read Visual Studio Code and Github Desktop Tutorial.pdf
Practice
How to add configure: https://www.youtube.com/watch?v=ABVeAXcRIJg
Procedures:
Syntax: Save your programs as yourfullname_lab1exN.c , where N is the number of exercise,
and check the program with different values.

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.

a. The first 2km is 15,000 VND


b. The next 250m will cost 2000 VND
c. If the travel distance is larger than 30km then each extra km will cost only
5000VND
Allow user to input the travel distance in km and print the amount of money to be paid.
Algorithm:
// Initialize km,cost=15000;
//input km
//print km
//if 2km <= km <=30
//  cost = 15000 + (km-2)*8000
//else if km>30
//  cost = 15000 + 28*8000+(km-30)*5000;
//end else if
//print result
// print cost
Introduction to C/C++ Course: IT116IU
International University – VNU HCM Date: 13 Sep. 2021
Dr. Ly Tu Nga Time: 4 hours

Result:

You might also like