SMA 2175 Computer Programming I Exam
SMA 2175 Computer Programming I Exam
1
i) The following program is supposed to find the square and cube of 5, but it has errors.
Rewrite the correct code [3 Marks]
#include<stdio.h>
void main()
{
int, x2, x3;
printf(“xsquare=%d ,xcubed=%d\n”, x, x2, x3);
}
c) Write a program to swap two integer numbers using pointers. The swapping operation
should be implemented using a function. The output should give the values before and
after the swap [5 Marks]
2
c) Explain any three advantages of C Programming language. [3 Marks]
c) Using a while loop write a program to compute the sum of the first n natural numbers.
[5 Marks]
d) Write a program in C that takes minutes as input, and display the total number of hours
and minutes. [5 Marks]