C language experiment in Wuhan University of Technology


Preface

The general content to be recorded in this article: The author's in-class experiment of the high-level language programming course in the first semester of the sophomore year.
Development environment: Visual Studio 2019


The following is the content of this article, the following cases are for reference

1. Program control statement

Problem description: 1. Find a three-digit digit: When n is 152, find the values ​​of the ones digit (digit1), tens digit (digit2) and hundreds digit (digit3) of n.
2. Fishing in three days and drying the net in two days: There is a Chinese saying "fishing in three days and drying the net in two days". Suppose someone starts "fishing for three days and drying the net for two days" from a certain day, and asks this person whether he "fishing" or "basking the net" in the next nth day? Try to write the corresponding program.
3. Calculate personal income tax: Assume that personal income tax is: tax rate × (salary -1600). Please write a program to calculate the income tax payable, where the tax rate is defined as: when the salary does not exceed 1600, the tax rate is 0; when the salary is in the interval (1600, 2500), the tax rate is 5%; when the salary is in the interval (2500, 3500] When the salary is in the range (3500, 4500), the tax rate is 15%; when the salary exceeds 4500, the tax rate is 20%.
4. Find the first n items in the sequence and (a + aa + aaa + aa) …A). Input two positive integers a and n, and find the sum of a + aa + aaa + aa…a (n a). For example, input 2 and 3, output 246 (2 + 22 + 222). Try to write Corresponding program.
5. Write a program, input a line of characters (the symbol "#" indicates the end of the input), and count the number of English letters, spaces, numbers and other characters.
6. If a number is exactly equal to its factor Sum, this number is called "finished number". For example: 6=1+2+3. Program to find all finished numbers within 1000.
7. Change coins. Change a change (more than 8 cents, less than 1 yuan, (Accurate to the minute) Change into coins of 5 cents, 2 cents and 1 cent. At least one of each coin. Enter the amount. How many exchange methods are there? For each exchange method, output the number of coins and coins of various denominations The total quantity. Try to write the corresponding program.

Two, arrays and functions

Problem description: 1. Use the function to count the number of specified numbers: input an integer, count and output the number of 2 in the number. The function countDigit(number, digit) is required to be defined and called. Its function is to count the number of digits in the integer number. For example, the return value of countDigit(10090, 0) is 3.
2. Use the function to judge the perfect square number: input a positive integer n and judge whether it is a perfect square number, if it is, output "YES", if not, output "NO". It is required to define and call the function isSquare(n) to determine whether n is a perfect square number.
3. Store the numbers in the array in reverse order: input a positive integer n (1< n≤10), then input n integers, and store them in array a. First store the n numbers in array a in reverse order, and then press Output n elements in array a in sequence. Try to write the corresponding program.
4. Output array element: input 1 positive integer n (1< n≤10), then input n integers of array a, and store the difference between all subsequent items in a minus the preceding items in array b, and press each row The 3 element format outputs array elements.
5. Try to write a program to select the largest element of each row in the two-dimensional array a to form a one-dimensional array b.
6. Connect two strings: the custom function implements the function of the system function strcat, and test this function in the main function.

3. Comprehensive programming

Problem description: 1. The use file contains the preparation of a simple addition and subtraction calculator: to prepare a simple addition and subtraction calculator, the format of the input calculation formula is: integer constant + operator + integer constant. It is required to write the addition and subtraction operations as functions: int add(int a, int b), int sub(int a, int b) and define them in add.h and sub.h files respectively. Then, write a separate cal.c file containing the main function to achieve the functions required by the topic.
2. Design a menu-driven student performance management program to manage the scores of n students in m subjects, and realize the following basic functions:
(1) Add student information and calculate the total score and average score.
(2) Able to modify and delete a student's information according to the student number.
(3) Able to display the performance information of all students.
(4) Able to sort by total score and student number.
(5) Able to query the basic information of the student according to the student number.
When the program is running, the menu format is as follows:
Management for Students' scores
1. Append record
2. List record
3. Delete record
4. Modify record
5. Search record
6. Sort in descending order by sum
7. Sort in ascending order by sum
8 . Sort in descending order by num
9. Sort in ascending order by num
It is required to organize the program structure in a modular way, and design each defined function reasonably.
3. (Optional) Design and implementation of the address book management program. The specific requirements are as follows:
(1) Enter the name and phone number of the contact person.
(2) Modify, add, and delete the address book.
(3) Query through various conditions (such as name or phone number, etc.).


to sum up

The experiment content has many questions, so the detailed code will not be listed. For details, please go to the link below to download the experiment report for viewing. Thanks for the support.
Link: Chong Chong Chong ~
Extraction code: 34hk
Copy this content and open the Baidu Netdisk mobile phone App, the operation is more convenient

Guess you like

Origin blog.csdn.net/mo_zhe/article/details/112484393