You are on page 1of 5

CSC2203 (F) / Page 1 of 5

INTI INTERNATIONAL UNIVERSITY

BACHELOR OF ENGINEERING (HONS) IN CIVIL ENGINEERING


BACHELOR OF ENGINEERING (HONS) IN MECHANICAL ENGINEERING
CSC2203: INTRODUCTION TO PROGRAMMING
FINAL EXAMINATION: JANUARY 2015 SESSION

This paper consists of SIX (6) questions. Answer any FOUR (4) questions in the
answer booklet provided. All questions carry equal marks.

Question 1

(a) What is the difference between break and continue statements?


(5 marks)
(b) Find the output of the following program:

i. int main(int argc, char **argv) {


int iValue=2;
switch(iValue) {
default: printf(“Not Valid ”);
case 1: printf(“ONE ”);
break;
case 2: printf(“TWO”);
break;
}
return 0;
}

ii.
int main(int argc, char **argv)
{
char acString[]=”Assignment”;
printf(“%d %d”,strlen(acString),sizeof(acString));
return 0;
}

iii. Find the output of the following program:


int main(int argc, char **argv) {
int aiArray[2][2]={10,20,30,40};
printf(“%d”,aiArray[1][1]);
return 0;
}
CSC2203 (F) / Page 2 of 5

iv. int main(int argc, char **argv)


{
char acString[20] = ”Programming”;
printf(“%d”,sizeof(acString));
return 0;
}

v. int main(int argc, char **argv)


{
int iValue=100;
int *piValue = &iValue;
*piValue = *piValue + 5;
printf(“%d”,iValue);
return 0;
}
(10 marks)

(c) Write a C program that request for an integer number and determine whether it
is prime or not a prime number.
(10 marks)

Question 2

(a) Write a program that accepts two numbers from a terminal and call a function
named min_max in main to determine the minimum and the maximum number.
By using the pointers, the value of minimum and maximum are send back to
main() and to be printed out.
(12 marks)

(b) Write a C program that reads in ten integer numbers and store them in an array
called Numbers[]. The program should display the total number of odd number
and total number of even number in the array and display the content
accordingly.

(13 marks)

Question 3

(a) Write a C program using nested for loop and produce the output shown below:

1x1 =1 1x2=2 1x3=3 1 x 4 =4


2x1 =2 2x2=4 2x3=6 2 x 4 =8
3x1 =3 3x2=6 3x3=9 3 x 4 =12
4x1 =4 4x 2 = 8 4 x 3 = 12 4 x 4 =16
5x1 =5 5 x 2 = 10 5 x 3 = 15 5 x 4 =20

(8 marks)
CSC2203 (F) / Page 3 of 5

(b) Trace the output from the following program:

#include <stdio.h>

main()
{
int i = 10;

do{
printf("Hello %d\n", i );
i = i -1;
if( i == 6 )
{
break;
}
}while ( i > 0 );
}

(5 marks)

(c) Write a C program that will request for a radius value. Pass the argument to a
function called fnArea() to calculate the area of the circle.
(12 marks)

Question 4

(a) Write a program that stores the following test marks in the array called Marks.
The program reads the contents of the test marks and display the scores and the
grade on the screen based on the following marks ranges.

Marks Grade Sample Output


0 – 49 F e.g Marks[0] = 88 A
50 – 69 C Marks[1] = 50 C
70 – 79 B .
80 – 100 A .
(12 marks)

(b) You can calculate your Body Mass Index (BMI) by using the following

formula:
BMI = Weight (kg)
Height (m) x Height (m)

Write a program that will calculate the BMI and display the following message
according to the BMI result calculated.
CSC2203 (F) / Page 4 of 5

BMI Reading Message


< 18.5 You are underweight
18.5 to 24 Your weight is desirable
25 to 29 You are overweight
>29 You are obese

(10 marks)
(c) What is the difference between scanf() and gets()?
(3 marks)

Question 5

(a) Write a code segment using a sentinel-loop structure to ensure marks entered by
the user is between 0 and 100. Display appropriate error message if an invalid
mark is entered.
(5 marks)

(b) Distinguish between the following terms:

(i) function passed by value and passed by reference.

(ii) scanf() and gets().


(10 marks)

(c) Write a function square() that will take an integer and return its square. Write
another function cube() that will take an integer and return its cube. Implement
the two functions, in a program to produce a neatly printed table containing a
list of integers, their square and their cubes as shown below. The integer should
run from 1 to 10.

Sample output:

Number Square Cube


1 1 1
2 4 8
3 9 27
4 6 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000
(10 marks)
CSC2203 (F) / Page 5 of 5

Question 6

(a) i. Define a structure with the following fields:-


Name
Address
City
Postcode
Age
Salary
(4 marks)
ii. Declare an array of 50 structures for the above ( a) .
(1 marks)
th
iii. Assign the following fields to the 10 record.

Name : Amit
Address :
City : Seremban
Postcode: 70300
Age : 20
Salary : $4,000

(5 marks)

(b) Write a C program that prompt for the number of names to be entered. Store the
name in an array called Names[]. Using bubble sort technique, sort the names
in ascending order. Display the number of passes done and the sorted list
(15 marks)

--THE END –
CSC2203(F)/JAN15/ JEYARANI/030315

You might also like