Professional Documents
Culture Documents
De Thi HK3 2022
De Thi HK3 2022
Quang
(Signature and Fullname) (Signature and Fullname)
a*= 3 : a = a*3
I. Multiple choice(6.0 pts)
a = 1;
a += 4 : a = a+4 = 5
1. Given the following command line, what value will be 3. The value of M after running the program is:
printed to the screen?
1 # include <s t d i o . h>
1 int x=5 , y =10; Tạo ra 2 biến nguyên là x và y với x = 5 và y= 10 2 int main ( )
2 float z ; tạo ra biến số thực z 3 {
3 z=( float ) x/y ; cho biến thực z = x/y = 5/10 = 1/2 = 0.5 4 int i =1 ,M=1 ,S=1; tạo biến số nguyên
4 p r i n t f ( " %.2 f " , z ) ; in ra biến số thực z :%f và phần .2 để in ra 2 số sau 5 while ( i <=3) vòng lặp while (<điều kiện>) : lặp đến khi nào điều
6 { kiện vẫn đúng
dấu phẩy
7 S+=M; i s m
8 M∗= i ; 1 2 1
(a) 0.00
9 i ++; 2 3 2
(b) 0.50 10 } 3 5 6
11 return 0 ; 4 x x
(c) 1/2 12 }
(d) All answers are incorrect
(a) 8
(b) 5
(c) 4
(d) 6
(c) ->
(d) * pointer to a variable : cái gì đó không phải structure
8. What is wrong about the structure in C language? (a) a=1, b=2, c=3, d=4
(a) A structure is a collection of elements that can (b) a=2, b=1, c=4, d=3
be of same datatype (c) a=1, b=2, c=4, d=3
(b) A structure is a collection of elements that can- (d) a=2, b=1, c=3, d=4
not be of different datatype
12. Given the following command line, what will be printed
(c) Elements of a structure are called members to the screen?
1 # include <s t d i o . h>
2 int main ( ) i a[i] Dk1 DK2 DK3
3 { 0 1 T F F
4 int a [ 5 ] = { 1 , 4 , 2 0 , 1 7 , 2 9 } ; 1 4 T T T
9. All keywords in C are in ... 5 int i ; 2 20 F T T
6 int Min=2 ,Max=5;
(a) Lower-Case letters 7 for ( i =0; i <5; i ++) 3 17 F F T
8 { 4 29 F F T
(b) Upper-Case letters 9 if ( ( a [ i ]<=Max) | | ( ( a [ i ]%2)==0) | | ( a [ i ]>=
(c) Camel-Case letters Min ) )
10 { dau hoac
(d) None of the mentioned 11 p r i n t f ( "%d\t" , a [ i ] ) ;
12 break ; ngat thang for, while
13 }
14 }
15 p r i n t f ( " done " ) ;
16 return 0 ;
10. Give the following program 17 }
1 # include <s t d i o . h>
i++ : 0, 1, 2 - 3
2 int main ( ) (a) 1 done
3 { ++i : 1, 2 - 3
4 int i =1; ++i (b) 1 4 20 17 29 done
5 for ( i =0; i <3; i ++) vòng lặp for
6 { (c) 4 20 17 29 done
7 p r i n t f ( "%d\t" , i ) ;
\t : cách
(d) done
8 }
9 return 0 ; i = 3 13. What value does the following command output to the
10 }
screen?
What will be printed to the screen with the following 1 p r i n t f ( " |%06.0 f | " , 1 2 3 . 1 2 3 ) ;
program?
(a) 012 (a) |123000|
(b) 0\t1 2 3 (b) |000123|
(c) 12 (c) |0123.1|
(d) 123 (d) All answers are incorrect
26. HCMUT-VNU students have a set of experimental data stored in a file showing pressure at several locations along the
nozzle.
Write a program using the C language to perform the following tasks
(0.5 pts) a) Write code to import data from file including ID (int), position along nozzle (float) and pressure value
(float). The structure of file will be showed as below
26.
1 # include <s t d i o . h>
2 # define SIZE 50
3 // b ) Create an array of struct of students to store all data .
4 struct Experimental_Data
5 {
6 int i d ;
7 float p o s i t i o n ;
8 float p r e s s u r e ;
9 }
10 int main ( )
11 {
12 int i d [ SIZE ] ;
13 float g1 [ SIZE ] , g2 [ SIZE ] ;
14 int i , j , n = 0 ;
15 float avg , sum=0;
16 /* a ) Write code to import data from file including
17 ID ( int ) , position along nozzle ( float ) and pressure value ( float ) .
18 The structure of file will be showed as below */
19 // openfile
20 FILE ∗ p F i l e = NULL;
21 p F i l e = f o p e n ( " Data . txt " , " r " ) ;
22 if ( p F i l e == NULL) {
23 p r i n t f ( " \ nUnable to open file " ) ;
24 return 0 ;
25 }
26 // read Data
27 while ( f s c a n f ( p F i l e , " % d % f % f " ,& i d [ n ] ,& g1 [ n ] ,& g2 [ n ] ) >0)
28 {
29 if ( i d [ n]==’ ’ ) continue ;
30 n++;
31 }
32
33 // b ) Create an array of struct of students to store all data .
34 struct Experimental_Data Exp_data [ n ] ;
35 for ( i =0; i <n ; i ++)
36 {
37 Exp_data [ i ] . i d=i d [ i ] ;
38 Exp_data [ i ] . p o s i t i o n=g1 [ i ] ;
39 Exp_data [ i ] . p r e s s u r e=g2 [ i ] ;
40 }
41
42 /* c ) sort the elements of the struct array from small to large positions along the nozzle
43 and calculate average pressure of data - set */
44 for ( i =0; i <n−1; i ++)
45 {
46 for ( j=i +1; j <n ; j ++)
47 {
48 if ( Exp_data [ i ] . p o s i t i o n >Exp_data [ j ] . p o s i t i o n )
49 {
50 int temp=Exp_data [ i ] . p o s i t i o n ;
51 Exp_data [ i ] . p o s i t i o n=Exp_data [ j ] . p o s i t i o n ;
52 Exp_data [ j ] . p o s i t i o n=temp ;
53 }
54 }
55 }
56 for ( i =0; i <n ; i ++)
57 {
58 sum+=sum ;
59 }
60 avg = ( float ) sum/n ;
61
62 /* d ) Print to the screen positions where pressure value larger than the average pressure . */
63 for ( i =0; i <n ; i ++)
64 {
65 if ( Exp_data [ i ] . p r e s s u r e >=avg )
66 {
67 p r i n t f ( " % f " , Exp_data [ i ] . p o s i t i o n ) ;
68 }
69 }
70 f c l o s e ( pFile ) ;
71 return 0 ;
72 }