Professional Documents
Culture Documents
STPM 2011 - ICT: Variable Description
STPM 2011 - ICT: Variable Description
1. a) Write declaration statements in C for each of the variables according to the descriptions
(3) given in the table below.
Variable Description
name Character string with a maximum of 30
characters
studentNumber Beginning with two letters followed by four
digits
classCode One letter
cgpaValue CGPA value with one decimal place
semester Current semester
[5 marks]
(b) Rewrite the C statements in (a) using a structure declaration named student.
[5 marks]
Answer
a)
char name, studentNumber, classCode;
float cgpaValue;
int semester;
b)
struct student {
char name[30];
char studentNumber[6];
char classCode[1];
float cgpaValue;
int semester;
};
Convert the formula to its equivalent statement in C, where variables num, x and y are
integers. [2 marks]
Using the C statement that you have obtained in (a), show the operation involved in
calculating the value of num if x = 10 and y = 5. [4 marks]
Answer
a)
int num, x, y;
num = ((3*x + y)/(y + 3)) + x;
b)
x = 10, y = 5
2
3. Draw a flow chart which reads and prints the first number that is multiple of 5 and is greater
(5) than 500. Assume that the number is named multipleNum and an initial value of integer 5 is
read. Hence, state the value of multipleNum. [7 marks]
Answer
#include <stdio.h>
void main() {
int multipleNum, i;
multipleNum = 5;
4. An element in an array is referred to by the name of the array followed by a subscript. Thus, the
first element of an array has a subscript zero.
Answer
a)
printf(“%c”, A[7]);
b)
scanf(“%f”,&B[10]);
3
c)
for (i = 0; i < 10; i++)
C[i] = 10;
d)
for (j = 0; j < 12; j++)
E[j] = D[j];
e)
#include <stdio.h>
void main ()
{
int F[30], i, SmallestValue, LargestValue;