1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Supplementary tasks c program structure and its components

6 1 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 6
Dung lượng 292,42 KB

Nội dung

1 Chapter 2 C Program Structure and its Components A Review A 1 List all the main components of a C program A 2 Identify each main component of a C program given as follows A 3 Give a name of the sour[.]

Chapter 2: C Program Structure and its Components A Review: A.1 List all the main components of a C program A.2 Identify each main component of a C program given as follows: A.3 Give a name of the source code file for the aforementioned C program in A.2 A.4 Suppose the norm of a vector (x, y) can be computed by the following function getVectorNorm() in the C language: (x*x + y*y)1/2 Rewrite the aforementioned C program in A.2 with the use of the function getVectorNorm() as follows: Identify the main components of the rewritten program and then determine which instruction is processed at the beginning A.5 Summarize the advantages of using coding standards in programming Give an example or demonstration along with each advantage A.6 Given a C program as follows Discuss the coding style used for writing this program A.7 Suggest at least five changes should be applied to the aforementioned C program in A.6 A.8 List the devices associated with the printf output function and the scanf input function, respectively A.9 Write conversion specifiers with printf and scanf to print and receive the five following special characters: percent (%), backslash (\), quotation mark (“), semicolon (;), bracket (}) A.10 Write a format control string to print a float number with 10 letters including the period (.) A.11 Write a format control string to receive a single character Explain what happens if the input data stream includes more than character such as: “ab”, “1a”, … A.12 Summarize the support of scan sets and inverted scan sets for receiving various string values appropriately A.13 Discuss the differences between the printf function and the scanf function in specifying the other arguments for their format control strings, respectively B Practice: B.1 Check which statements are not correct to print the specified data as the expected output as follows Suggest their correct forms a printf("This is an example of printing literal characters.\\n\n"); Expected output: This is an example of printing literal characters b printf("%f\n\n", 10); Expected output: 10.000000 c printf("#%3d#\n\n", 10); Expected output: # 10# d printf("#% d#\n\n", 10); Expected output: # 10# e printf("#%+3d#\n\n", 10); Expected output: #+10# f printf("#% - 3d#\n\n", 10); Expected output: #10 # g printf("#%*.*f#\n\n", 10, 3, 100.123456789); Expected output: # 100.123# h printf(“%c\n\n”, “Practice B.1.”); Expected output: Practice B.1 i printf("\"%-15s\"", "Practice B.1."); Expected output: “Practice B.1 “ j printf(“#%015s#”, “Complete B.1.”); Expected output: #00Complete B.1.# B.2 Write a statement corresponding to each printing requirement as follows: a Print a natural number 98765 as-is b Print a natural number 98765 with a plus sign c Print a natural number 98765 left justified in a 15-digit field with digits d Print a natural number 98765 left justified in a 15-digit field with digits preceded by e Print a real number 98765.432198765 right justified in a 15-digit field with digits and digits of precision f Print a real number 99998765.432198765 left justified in the scientific format g Print a real number 998765.432198765 left justified in a 10-digit field h Print “90% of the exercises haven’t been completed; however, let’s “try our best”” i Print a string “Nearly complete all the exercises” on one line and a natural number 10 on the next line in the variables sNote and iNumber, respectively B.3 Write a C program to print the following stars (*) in the specified shape STAR based on a 9x12 grid: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * B.4 Describe what should be input for the variables with each following statement: a scanf("%d", &iNumber); b scanf("%d*%d", &iNumber1, &iNumber2); c scanf("%c %f", &cChar, &fNumber); d scanf("%[^0123456789]", sString); e scanf("%s%d", sString, &iNumber); f scanf("%3d%f", &iNumber, &fNumber); B.5 Write a C program to receive a sequence of numbers as a string using an appropriate scan set Input 1: 012345 Output 1: 012345 Input 2: asdf012345 Output 2: Input 3: 012345asdf Output 3: 012345 B.6 Write a C program to receive your name and favorite date with the following conditions: - Your name is written using only lower-case letters - Your favorite date is in the form of dd-mm-yyyy Input 1: chau; 18-01-2017 Output 1: Name = “chau”; Date = 18/01/2017 Input 2: Chau Output2: Name = ; Date = Input 3: chau; 18/01/2017 Output 3: Name = “chau”; Date =

Ngày đăng: 11/04/2023, 18:46