Tải bản đầy đủ (.pdf) (2 trang)

Lab 6 functions

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (202.69 KB, 2 trang )

Course: Programming Fundamentals (C language)
LAB 6 – Functions
Main content:
1.
2.
3.
4.

Get used to standard library functions
Get used to function definitions and function calls
Start more complex data processing
Check coding styles

Practice:
1. Get used to standard library functions
1.1. Write a C program to approximate a value of the function ex using a function for your
approximation and then use a corresponding function pow() in the standard library to
evaluate your approximated values.
1.2. Write a C program to check if a user has entered an alphabetic letter from the keyboard till
the user enters #. How many times has the user entered an alphabetic letter? What is the
percentage of that event? For checking a character input by a user, define and use a
corresponding function and then use a standard function provided by the library.
1.3. Write a C program to compute an average grade of at least three courses that you studied
last semester. It is supposed that the average grade is rounded with two digits after the
floating point. Can we use any existing function in the standard library to round a floating
point number in such a context? If yes, compare your rounded number and the one from
the function in the standard library.
2. Get used to function definitions and function calls
2.1. Given the information of a few students as follows, write a C program to compute the
percentage of the students enrolled in 2014 using functions.
ID


14102054
14210351
15103032
15202412
14113089
14200768

Name
John Smith
Peter Brown
Liz Blair
Tony Blade
White Depp
Daisy Cruise

Hometown
Chelsea
London
London
London
Chelsea
London

2.2. Write a C program to count how many numbers X in the Fibonacci series are between the
range (min, Max), i.e. X > min and X < Max and min < Max, where min and Max are two
natural numbers given by a user from the keyboard using functions.

1



2.3. Write a C program to print the reversed numbers of N integer numbers input by a user from
the keyboard using functions. How many numbers have 4 digits?
3. Start more complex data processing
3.1. Write a C program using functions for question 1.2 in Lab 5.
3.2. Write a C program using functions for question 2.3 in Lab 5.
3.3. Write a C program using functions for question 3.2 in Lab 5.
3.4. Write a C program to recommend the place to a tourist based on his/her current position in
such a way that he/she needs to travel in the shortest distance using functions. How much
does it cost him/her for travelling by taxi?
Information about places for recommendation
Location
Place
X
Walking street
23.5
Post office
2.8
Church
5.1
Independence palace
1.6

Y
10
4.3
17
2.9

Information about cost
Distance (km)

Unit price (K)
0<=5.0
10.0
5.0<=10.0
9.5
10.0<=18.5
8.2
> 18.5
7.5

Tourist
John Smith
Peter Brown
Alice Depp
March Carter

Information about tourists
Location
X
2.4
12.4
5.2
4.8

Y
5
5
8.3
7.5


4. Check coding styles
For each C program that you have written, check coding styles with the following points:
- How have you used blank lines?
- How have you used tabs for alignment?
- How have you used comments in your source code files?
- Above all, how about your naming conventions? What have you named in your source code
files?

2



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×