Pages

Thursday, November 12, 2015

Computer Science Past Question On Computer Laboratory 2012/2013

UNIVERSITY OF CALABAR, CALABAR
DEPARTMENT OF MATHS/STATS & COMPUTER SCIENCE
SECOND SEMESTER EXAMINATION 2012/2013 SESSION
COURSE CODE: CSC 3381
COURSE TITLE: COMPUTER LAB III A TIME: 1Hr 30mins.
INSTRUCTION: ANSWER ANY TWO QUESTIONS IN SECTION A. SECTION B IS COMPULSORY



SECTION A 1hr

1. a. What are data types? Using C or C++ syntax, declare variables of three different types.
b. What are Control Structures? Mention and discuss any two in C or C++.
c. Write a C or C++ function and main program to produce prime numbers to a given n.

2. a. What is an array? Declare an array of 30 characters and a pointer to the array in C or C+++.
b. Explain four keywords associated with data output in C/C++.
c. Write a C or C++ function and main program to produce the Greatest Common Divisor for any
given integers P and Q.

3. a. What are preprocessor directives? List five and state their uses.
b. Compare the use of scanf and cin in C and C++ respectively.
c. Write a C or C++ function and main program to produce the Factorial of any given integer n.

4. a. What are pointers? Declare a pointer to a char type variable.
b. Compare the use of printf and cout in C and C++ respectively.
c. Write a C or C++ function and main program to produce the Fibonacci numbers to any
given integer n. (where n>1)


SECTION B 30mins

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <conio.h>
void main()
{
long n, dec, mult, r, base;
clrscr();
printf("\n Enter a base : "); scanf("%d",&base);

printf("\n Enter a number : "); scanf("%d", &n);
dec=0; mult=1;
printf("\n Decimal equivalent of base %1d number %1d is ", base, n);
while (n!=0)
{
r = n % 10;
n /= 10;
r = r * mult;
dec = dec + r;
mult *= base;
} //while
printf("%d", dec);
} //main

Questions
1. Number and explain what each line of the code above does.
2. Discuss the kernel of the While loop with an execution frame.
3. What is the entire program doing?
4. Is this program a C or a C++ convention? Hence what changes would make it C or C++