0% found this document useful (0 votes)
223 views4 pages

C/C++ Programming Lab Overview

This document provides an introduction and instructions for a lab on using Visual Studio Code for C/C++ programming. The lab objectives are to learn how to install and use Visual Studio Code, use basic programming constructs like if/else statements and while loops, and fix bugs in code. The document includes 4 practice exercises for reversing digits of a number, finding minimum and maximum values in a list, evaluating a mathematical expression, and calculating taxi fares. Pseudocode algorithms are provided for each exercise. Students are instructed to save their files in a specific format and collect any bugs encountered.

Uploaded by

Sơn Xuân
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
223 views4 pages

C/C++ Programming Lab Overview

This document provides an introduction and instructions for a lab on using Visual Studio Code for C/C++ programming. The lab objectives are to learn how to install and use Visual Studio Code, use basic programming constructs like if/else statements and while loops, and fix bugs in code. The document includes 4 practice exercises for reversing digits of a number, finding minimum and maximum values in a list, evaluating a mathematical expression, and calculating taxi fares. Pseudocode algorithms are provided for each exercise. Students are instructed to save their files in a specific format and collect any bugs encountered.

Uploaded by

Sơn Xuân
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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 [Link]
Practice
How to add configure: [Link]
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