CSC2203(F)/ Page 1 of 6
INTI INTERNATIONAL UNIVERSITY
BACHELOR OF ENGINEERING (HONS) IN CIVIL ENGINEERING
BACHELOR OF ENGINEERING (HONS) IN MECHANICAL ENGINEERING
CSC2203: INTRODUCTION TO PROGRAMMING
FINAL EXAMINATION: AUGUST 2015 SESSION
Answer ALL TWO (2) compulsory questions in Section A and ANY TWO (2) questions in
Section B in the answer booklet provided. All questions carry equal marks.
Section A
Answer ALL questions in this section. All questions carry equal marks.
Question 1
a) Write down the rules for naming C variable?
(5 marks)
b) Identify which of the following are valid type int, double or char constants in C and which
are not. Identify the data type of each valid constant.
i) 36
ii) ‘I’
iii) .945
iv) 4,76
v) ‘$#’
(5 marks)
c) Write a C program that reads characters until newline, store it in a character array and
terminate with null character. Then print all the characters read except the newline.
(15 marks)
CSC2203(F)/ Page 2 of 6
Question 2
a) Find any errors in the following program
include <stdio.h>
int main()
{ a int = 100;
if ( a < 20 )
printf("%f is less than 20\n" );
else
printf("%d is not less than 20\n" );
prinf("value of a is : %d\n", a); }
(5 marks)
b) Write a program in C to accept distance in miles as an input from the user and pass the user
input to a function that will convert the distance from miles to kilometers using the formula
kilometers per mile = 1.609.
(10 Marks)
c) The following C program accepts two integer inputs and one character input from the user. If
the character input is an arithmetic operator, it will perform the operation and display the
result. If the character entered is not an arithmetic operator, it will display error message and
quit. Complete the program.
#include <stdio.h>
void main()
{
int _____
char op;
printf("Enter any operator \n");
____________________;
printf("Enter first number \n");
___________________;
printf("Enter second number \n");
scanf("%d",&b);
__________
{
case '+' : c=a+b;
printf("%d + %d = %d \n",a,b,c);
_______
case '-' : c=a-b;
printf("%d - %d = %d \n",a,b,c);
________
case '*' : c=a*b;
printf("%d * %d = %d \n",a,b,c);
__________
case '/': c=a/b;
printf("%d / %d = %d \n",a,b,c);
_________
CSC2203(F)/ Page 3 of 6
case '%': c=a%b;
printf("%d %% %d = %d \n",a,b,c);
________
________: printf("Sorry No operations can be
performed for this operator %c \n",op);
break;
}
}
(10 marks)
Section B
Answer ANY TWO (2) questions in this section. All questions carry equal marks.
Question 1
a) Consider the following declaration and definition
typedef struct FUN
{
char x;
char *y;
int z[20];
} FUNNY;
struct FUN fn1;
FUNNY fn2;
struct FUN fn3[10];
FUNNY fn4[50];
Determine which of the following assignment statements are valid and which are invalid. If
invalid, explain the error.
i) fn1.x = 'b';
ii) fn2.y = 'b';
iii) fn3[4].z[5] = 234;
iv) fn4[23].y = '1234';
v) fn4[23] = fn3[5];
(15 marks)
b) What would be printed from the C program given below if a is entered as 3 and b is entered
as 5?
#include <stdio.h>
int strange(int x, int y);
int main(void)
{
int a,b,r,s;
scanf("%d %d", &a, &b);
r = strange(a,b);
CSC2203(F)/ Page 4 of 6
s = strange(b,a);
printf("%d %d", r, s);
return 0;
}
int strange(int x, int y)
{
return(x-y);
}
(10 marks)
Question 2
a) If x=2, y=3 and z=1, what is the value of each of the following expressions?
i) x+2/6+y
ii) y–3*z+2
iii) z – (x + z) % 2 + 4
iv) x – 2 * (3 + z) + y
v) y++ + z-- + x++
(5 marks)
b) Trace the output of the following program
#include <stdio.h>
void main()
{
int a,b,c;
int *p,*q,*r;
a=6;
b=2;
p=&b;
q=p;
r=&c;
p=&a;
*q=8;
*r = *p;
*r = a + *q + *&c;
printf("%d %d %d \n", a,b,c);
printf("%d %d %d \n", *p,*q,*r);
}
(5 marks)
CSC2203(F)/ Page 5 of 6
c) Write a C program to get a integer input from user and check and display the user input is
odd or even number.
Sample output:
Enter a value: 7
7 is an odd number
(5 marks)
d) The following C program multiplies two fractions and prints the result. Complete the
program.
#include <stdio.h>
typedef struct
{
____________
____________
} FRACTION;
int main(void)
{
_____________
_____________
_____________
printf("write the first fraction in the form of x/y: ");
scanf("%d %d",&fr1.numerator, &fr1.denominator);
printf("write the second fraction in the form of x/y: ");
______________________________________
res.numerator = fr1.numerator * fr2.numerator;
_____________________________________
printf("\n The result of %d/%d * %d/%d is %d/%d",
fr1.numerator, fr1.denominator, fr2.numerator,
fr2.denominator, res.numerator, res.denominator);
return 0;
}
(10 marks)
Question 3
What would be printed from the following program segments?
a) x=12;
while (x>7)
{
printf(“%d \n”, x);
x--;
}
(5 marks)
CSC2203(F)/ Page 6 of 6
b) for (x=12; x>7; x--)
printf(“%d \n”, x);
(5 marks)
c) x=12;
do
{
printf(“%d \n”, x);
x--;
} while (x>7);
(5 marks)
d) x=12;
while (x<7)
{
printf(“%d \n”, x);
x--;
}
(5 marks)
e) for(x=12; x<7; x--)
printf(“%d \n”, x);
(5 marks)
-The End-
CSC2203(F)/Aug2015/Dr.Chockalingam/25.11.2015