QUESTION 1
This is a compulsory question related to C programming constructs. You are only required
to write code snippets as shown in the example below:
Sample
Question:
Write code that outputs on the screen fifteen asterisks on the same line.
Sample Answer:
for(i = 0;i < 15;i++)
{
printf("\*");
}
a)
Using only one
printf
statement, write the required code to produce the following
output:
The overall le
ngth of an A320 aircraft is 123’ 3”.
The wingspan is 117’ 5”.
(3 marks)
b)
A variable of type
float
named
p
h
i
holds the value
1.61803
.
Write a statement to
output on the screen the contents of
p
h
i
to
two
decimal places.
(3 marks)
c)
Using only
one
for
loop and
one
printf
statement, w
rite the required code to output
on separate lines the
square values
of the numbers between 1 and
n
, where
n
is a
variable of type
int
.
(3 marks)
d)
Using
one
while
loop and
no
selection statements, w
rite the required code to
ask the
user to enter an examination mark between 0 and 100. If the mark entered by the
user is not within the range of 0 to 100
,
then the user should be asked to re
-
enter the
mark.
This should be repeated until a valid mark is entered.
(3 marks)
e)
char
puzzle[10][10]
is a two
-
dimension array of characters. Using two nested
for
loops, write the required code to initialise all the elements of this array to an asterisk
(\*).
(3 marks)
(Total of 15 marks
user