You are on page 1of 7

Marking Scheme of Programming Fundamentals Using

C
Module code: SFPPF301
Year 1
Term 1
Number of Hours per week: 5
Duration: 180 minutes
Date: 25/11/2022
Maximum Marks: 50
Instructions:
1. This question paper has two parts: Part 1: Answer by
True or False, Part 2: Open questions.
2. Do all questions of part 1.
3. In Part 2, answer questions from 1 to 8 and choose
one question between questions 9 and 10
4. For questions 9 or 10, give the list of steps,
pseudocode and the flowchart
Instructor: HATANGIMBABAZI Hilaire

I. Part 1: Answer by true or False


1. In a 32 bits computer system: /3 marks
a. The size of integer is 32 bits Answer: True
b. The range of unsigned characters is from 0 to 256 Answer: False
(0 to 255)
c. The format specifier of int is %d or %i Answer: True
2. Given x=5, y=3, z=1
a. The Boolean expression (x < 1) OR (x > 9) is evaluated to true /1
mark Answer: False ((x < 1) OR (x > 9) is false)
b. The Boolean expression (x MOD y) >= y is evaluated to false /1
mark Answer: True
3. With the two-dimensional array myArray with elements assigned as
indicated below: /3 marks

myArray ← [
[1, 2, 3],
[2, 4, 6],
[3, 6, 9],
[4, 8, 12]
]
a. myArray[3][1] evaluates to 8 Answer: True
b. myArray[0][0]+myArray[3][2]=14 Answer: False (myArray[0]
[0]+myArray[3][2]=13)
c. myArray[1][1]←16 is to replace 4 by 6 in mayArray Answer: False (To
replace 4 by 16 in myArray)

II. Part 2: Open questions


1. Define the following concepts: /10 marks
- Compiler
Answer: A compiler software which is used to translate high level
language into machine level language
- Interpreter
Answer: An interpreter works as a compiler, but it translates the
program instruction by instruction.
- Computer program
Answer: A computer program is a collection of the instructions
necessary to solve a specific problem when it is executed by a
computer.
- Algorithm
Answer:
- An Algorithm specifies a series of steps that performs a
particular computation or task.
- It is a step by step procedure of solving a problem.
- Variable (in c language)
Answer: In programming, a variable is a container (storage area) to
hold data.
2. What are categories of low level programming languages? /1 mark
Answer: Low level languages are categorized in assembly language and
machine language
3. Explain two among the advantages of high level programming languages.
/2 marks
Answer: Advantages of high level programming languages are:

● High-level languages are relatively easy to learn and much faster


to program in.
● Statements within these languages look like the natural English
language, including mathematical operators making it easier to
read, understand, debug and maintain.
● Complexed assignment statements such as
x=(sqr(b^2-4*a*c))/(2*a)
● Allowing the programmer to show how the algorithm will solve a
problem in a clearer and more straightforward way.

● Specialized high-level languages have been developed to make


the programming as quick and easy as possible for particular
applications such as SQL, specially written to make it easy to
search and maintain databases. HTML, CSS and JavaScript
were also developed to help people create web pages and
websites.

4. Write a C program which asks/prompts the user to enter three numbers.


The program should then calculate their sum and their average and
output them on the console. /6 marks
Here is the sample of output of the program:

Answer:

5. Explain the role of statements started by # in a C program /1 mark


Answer: is a preprocessor command/directive. This command tells
compiler to include the contents of stdio.h (standard input and output) file
in the program.The stdio.h file contains functions such as scanf() and
print() to take input and display output respectively
6. What are the characteristics of a good Algorithm? /5 marks
Answer: The characteristics of a good algorithm are:

1. Input and output should be well defined with precision.


2. Each step in an algorithm should be clear and unambiguous.
3. An algorithm should be most effective among many
different ways to solve a problem.
4. An algorithm should be human understandable,
it shouldn't have computer code. Instead, the
algorithm should be written in such a way that it
can be used in similar programming languages.
5. A good algorithm should be programming
language independent, ie can be implemented by
any software developer using any programming
language
7. Write the pseudocode of an Algorithm to find the sum of odd numbers
between 0 and any given number, n (n is a positive integer). /6 marks
Answer:
START
VAR sum←0, n
INPUT n
FOR i←0 TO n
IF i MOD 2 = 1 THEN
Sum←sum + i
ENDIF
ENDFOR
OUTPUT sum
STOP
8. Explain the reason why the range of signed characters in a computer
system in which the memory size reserved for a character variable is 1
Byte is [-128, +127] /2 marks
Answer:
The size of a signed character is 8 bits (1 Byte). The first bit (Most
Significant bit) is reserved for the sign and it is 1 if the sign is - and 0 if it
is +. This means that the first character of the range is 10000000
(Corresponding to 128 in Decimal) and the last one is 01111111
corresponding to 127 in Decimal. This implies that the range of signed
characters is is [-128, +127]
9. Define an algorithm to add the digits of any given positive number n. For
example, if n=536, the algorithm will calculate and return 5+3+6 which
is 14. /9 marks
Answer:
- List of steps
1. Start
2. Variables declaration: n to store any positive number, sum
to store the sum of digits in n. Initialize sum to 0
3. Get the value of n
4. If n modulus 10 is zero, change its value to n/10, else
change it to (n-(n modulus 10))/10 and calculate the sum as
sum+(n modulus 10). Repeat this until n is less than 0
5. Output the sum
6. Stop
- Pseudocode

START
VAR n, sum←0
INPUT n
WHILE n>0
IF (n MOD 10)=0 THEN
n←n/10
ELSE
n←(n-(n MOD 10))
sum←sum+(n MOD 10)
ENDIF
ENDWHILE
OUTPUT sum
STOP
- Flowchart

10. Define an algorithm to give the multiplication table of a given


number n (be limited to 10 entries, from 1*n to 10*n) /9 marks
Answer
- Pseudocode
START
VAR n, i
INPUT n
FOR i←1 TO 10
OUTPUT n*i
ENDFOR
END/STOP
- List steps
1. Start
2. Declare n, i
3. Initialize i to 1
4. Output n*i
5. Repeat 4 until i is 10
6. Stop
- Flowchart

___________________________END______________________________________________

You might also like