1 HCMC University of Technology and Education Faculty for High Quality Training ECET Final exam at the end of the semester 2, 2016-2017 Subject: Introduction to C programming language
Trang 11
HCMC University of Technology and Education
Faculty for High Quality Training
ECET
Final exam at the end of the semester 2, 2016-2017 Subject: Introduction to C programming language Subject code: CPRL130064E
Number of pages: 06 pages Duration: 75 minutes
Used paper documents
Students work directly on the exam and submit all
Supervisor Signature 1 Supervisor Signature 2
Points and Signatures
The first marking
lecture
The second marking lecture First and last name:
Student ID: Order number: Room:
Question 1: (2.0 points) Give a following program, please perform:
b) Show results on the screen after performing the program?
# #include <stdio.h>
I t main(void)
{
int a = 12, b = 6, c = 17, d;
if ((a >= b) || (b<c))
{
a +=++ c;
b = a - c;
d = c%b;
}
else
{
b += c;
c = ++a - b;
d = (b + c) / a;
}
printf("a:%d\n", a);
printf("b:%d\n", b);
printf("c:%d\n", c);
printf("d:%d\n", d);
return 0;
}
a) a flowchart
b) Results on the screen
………
………
Trang 22
Question 2: (2.0 points) Give a following program, please perform:
a) Show results on the screen after performing the program?
b) Write Pseudocode? c) Rewrite this program using “do…while”? #include <stdio.h> void main() { int i; for (i = 15; i>0; i)
printf("%d \t", i); } a) Results on the screen:
b) Pseudocode:
c) Rewrite using “do…while”:
Question 3: (1.0 points) What does the following program print?
#include<stdio.h>
int main (void)
{
unsigned int row = 4; // initialize row
unsigned int column; // define column
while (row >= 1) // loop until row < 1
{
column = 1; // set column to 1 as iteration begins while (column <= 10) // loop 10 times
{
if (row % 2 == 0)
printf("%s", "@"); // output else
break;
++column; // increment column
Trang 33
} // end inner while row; // decrement row printf("\n"); // begin new output line } // end outer while
} // end function main
Question 4: (1.0 points) Show results on the screen after performing a following program: #include <stdio.h> void main() { int a[6] = { 1, 2, 3, 4, 5, 6}; int *p1 = &a[1]; int *p2 = &a[3]; *p1 = *p2 + 4; *(p1 - 1) = *p2 - 5; *(p2 + 1) = a[2] + a[3]; *(p2 + 2) = *(p1 - 1) + *p1; printf("%d %d %d %d", a[0], a[1], a[4], a[5]); }
Question 5: (2.0 points) Edit bugs of a following program:
The program
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void ArrayInput(int *a, int n);
void ArrayPrint(int *a, int n)
void ArraySquare(int *a, int *b, int n);
Edit bugs
Trang 44
int main(void)
{
int n;
printf("\n Input element number of array: ");
scanf("%d", n);
int *a;
int *b;
a = (int *)malloc(n * sizeof(int));
b = &(int *)malloc(n * sizeof(int));
printf("\n Input values of the array\n");
ArrayInput(a, n);
printf("\n Solve square of the array\n");
ArraySquare(a, b, n);
ArrayPrint(a, n);
ArrayPrint(&b, n);
return 0;
}
void ArrayInput(int *a, int n)
{
for (int i = 0; i < n; i++)
{
printf("Input element %d of the array: ", i);
scanf("%d", &a + i);
}
}
void ArrayPrint(int *a, int n)
{
for (int i = 0; i < n; i++)
printf("%d \t", a + i);
printf("\n");
}
void ArraySquare(int *a, int *b, int n)
{
for (int i = 0; i <= n; i++)
{
*(b + i) = *(a + i) *(a + i);
}
}
Trang 55
Question 6: (2 points) Write a complete program which executes functions as follows:
a) Create a structure type, named SensorNode, to describe a Sensor Node The Sensor Node will collect temperatures which are used to avoid forest fires, and includes information as follows:
Node Code (named NodeID): integer format
Node Name (named NodeName): string format
Temperature value (named Temp): real number format
b) Enter information including Node Code, Node Name, and Temperature value of 10 different Sensor Nodes
c) Print out a Node Name which collects the highest temperature value
d) Print out the average temperature of these 10 Sensor Nodes
e) Indicates how many Sensor Nodes have temperatures greater than 38.5 Print all information of these Sensor Nodes on the screens
Trang 6
6
Notation: Supervisor officials are not allowed to explain the exam questions
[ELO 1.3]: Demonstrate command syntax, operation and application of
branching and iteration structures in C language
Questions 1, 2, 3
[ELO 1.5]: Present how the pointer is declared and how to use the
pointer to retrieve the memory
Questions 4, 5
[ELO 1.7]: Define structure type and use structure variables to store and
manage data
Question 6
[ELO 2.1]: Analyze the programming requirements from which to build
a flowchart, a complete program
Questions 1, 2, 6
[ELO 3.1]: Apply control structures, apply data manipulation, build
support functions to design and solve application programming
requirements
Questions 2, 6
June 07th, 2017
Head of ECET