CCSB163 Final - Mar 2007.pdf - MetaLab - Universiti Tenaga Nasional
CCSB163 Final - Mar 2007.pdf - MetaLab - Universiti Tenaga Nasional
CCSB163 Final - Mar 2007.pdf - MetaLab - Universiti Tenaga Nasional
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Question 3<br />
(a) Change program fragment below from do–while loop to the equivalent while<br />
loop.<br />
x = 0;<br />
do{<br />
printf(“%d\n”, x);<br />
x++;<br />
}while(x < 100);<br />
[4 marks]<br />
(b) Write a C program fragment using for loop to calculate x y (x to the power of y)<br />
where x and y are variables.<br />
(e)<br />
[5 marks]<br />
Write a C program fragment using nested for loops to produce the diagram<br />
below<br />
Question 4<br />
BBBBBBBBB<br />
BBBBBBB<br />
BBBBB<br />
BBB<br />
B<br />
[6 marks]<br />
The function chr2val below is supposed to return the equivalent integer value of<br />
the character in input_digit if it is a valid digit character. Otherwise, it will<br />
return -1. Fill up the FIVE blanks accordingly<br />
________ chr2val (char input_digit)<br />
{<br />
}<br />
if (________ && ________)<br />
else<br />
return ________;<br />
return ________;<br />
[5 marks]<br />
Semester 2 2006/2007<br />
Page 10 of 11<br />
Principles of Programming