0% found this document useful (0 votes)
53 views3 pages

Computer Programming Exam Questions

The document is an examination paper for the Bachelor of Science in Electronic and Computer Engineering at Jomo Kenyatta University, covering topics in computer programming. It includes questions on algorithms, variables, control statements, arrays, and pointers, requiring students to demonstrate their understanding of programming concepts and C language syntax. Students are instructed to answer question one and any two additional questions within a two-hour timeframe.

Uploaded by

kiribalaura
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views3 pages

Computer Programming Exam Questions

The document is an examination paper for the Bachelor of Science in Electronic and Computer Engineering at Jomo Kenyatta University, covering topics in computer programming. It includes questions on algorithms, variables, control statements, arrays, and pointers, requiring students to demonstrate their understanding of programming concepts and C language syntax. Students are instructed to answer question one and any two additional questions within a two-hour timeframe.

Uploaded by

kiribalaura
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

W1-2-60-1-6

JOMO KENYATTA UNIVERSITY OF AGRICULTURE AND


TECHNOLOGY
UNIVERSITY EXAMINATIONS 2017/2018
EXAMINATIONS FOR THE DEGREE OF BACHELOR OF SCIENCE IN
ELECTRONIC AND COMPUTER ENGINEERING
ICS 2102: INTRODUCTION TO COMPUTER PROGRAMMING
DATE: JANUARY 2018 TIME: 2 HOURS
INSTRUCTIONS: ANSWER QUESTION ONE AND ANY OTHER TWO QUESTIONS

QUESTION ONE

a) The “/n” character does what operations (1 mark)

b) Explain the following (5 marks)

1) Algorithm
2) Pseudo code
3) Arithmetic operations
4) Syntax errors
5) Semantic errors

c) Discuss four properties of a good algorithm (4 marks)

d) What is a variable? Which symbol separates variable names? (3 marks)

1) &
2) ;(period)
3) ‘ (apostrophe)
4) ,(comad)
5) ;(semicolon)

e) What is a keyword? State two keywords of C program (3 marks)

f) Write the syntax if the if-else statement (2 marks)

g) State and explain three logical operators (6 marks)

h) What is the purpose of break statement (2 marks)

i) What will be the output of the following program (4 marks)


Void main (){
int a=10;
Print f ( “”%d”, aJ;
{
int a=20;
Print f( “%d”, a J;
}
Print f %d”, aJ;
}

QUESTION TWO

a) Explain the if-else statement execution with its flowchart (5 marks)

b) For the following program fragment, derive the output generated by


print f statement (3 marks)

int val 2 =255;


float num=79.54123;
print f “%4d, %x, %7.3, %8.3e”, val 2, val2,
num, num;

c) Explain the concept of array of pointers with example (6 marks)

d) Explain the representation of two-dimensional array with example


(6 marks)

QUESTION THREE

a) Design an algorithm to add two numbers and display the results.

b) Describe the process of dedaring a function in C program.

c) Find out errors in the following program component and justify the
same (5 marks)

float i ;
int P=0;
for (i=0; i=10; i+=2)
{
P=i*2;
Printf ( “%d”, I, P);

d) Explain with example the array of structures (6 marks)

QUESTION FOUR

a) Write a program to find whether the given year is a leap or not (6


marks)
b) Explain a function of two parameters num 1 and num 2 and return the
maximum value (4 marks)

c) Explain the concept pointer’s arithmetic operations (4 marks)

d) Explain the meaning of the following statements with reference to


pointers (6 marks)

1) int*ptr, m=8;
2) *ptr =m;
3) ptr=$m;

Common questions

Powered by AI

In a nested block structure with shadow declarations, each block can have its own separate scope for variables with the same name. The output of such a program segment depends on which variable (shadowed or original) is accessed in each block. For instance, if a variable 'a' is declared in both the main block and a nested block, the inner block accesses its own 'a', while the outer block accesses the original 'a'. Therefore, the output would show values defined by the scope from which each 'a' is accessed .

To determine if a year is a leap year, the algorithm checks divisibility conditions: a year is a leap year if divisible by 4, except for end-of-century years, which must also be divisible by 400. The algorithm involves: 1) Checking if the year is divisible by 400 (leap year), 2) Else, checking if divisible by 100 (not a leap year), 3) Else, checking if divisible by 4 (leap year), and 4) Not satisfying any is not a leap year. This logic effectively captures leap year rules based on the Gregorian calendar .

Understanding the difference between a function's declaration (prototype) and its definition is crucial because it distinguishes between specifying what a function does and actually implementing it. A declaration introduces the function's signature to the compiler, typically outside main, enabling usage in different files, while the definition contains the executable code inside the function body. Example: `int add(int, int);` is a prototype, and `int add(int a, int b){ return a + b; }` is its definition, ensuring modular code and separate compilation units .

A good algorithm is defined by the properties of correctness, efficiency, finiteness, and clarity. Correctness ensures that the algorithm produces the correct output for all valid inputs. Efficiency refers to the appropriate use of computational resources, like time and memory. Finiteness means that the algorithm must terminate after a finite number of steps. Clarity implies that the algorithm should be easy to understand and follow, making it maintainable and modifiable .

In C programming, a variable is a storage location identified by a memory address and a symbolic name, allowing programmers to store and manipulate data. The comma ',' is commonly used to separate multiple variable names declared in a single statement .

Pointer arithmetic in C involves operations relative to the size of the data type being pointed to. Unlike regular arithmetic that increments values by 1, pointer arithmetic increases a pointer's address by the size of its base type. For instance, incrementing an int* moves 4 bytes forward on a 32-bit system. This feature is particularly useful for iterating through array elements elegantly with pointer incrementation instead of index-based access .

Syntax errors occur when code deviates from the grammatical rules of the programming language, typically detected during compilation, preventing the program from running. Semantic errors occur when code executes but does not perform as intended, usually due to incorrect logic or operation flow. Syntax errors stop the program from running, while semantic errors lead to unexpected results during execution .

An array of pointers is a collection, each element of which is a pointer to a variable, used for storing addresses, for instance, of strings. In contrast, a pointer to an array points to an entire array of variables. For example, `int *ptrArr[5];` can store addresses of int variables, whereas `int (*arrPtr)[5];` points to an int array. This distinction provides flexibility in data management strategies, allowing access to elements or entire collections efficiently .

Logical operators in C are used to perform logical operations on expressions, enabling decision-making in code. Three primary logical operators are the AND operator '&&', which returns true if both operands are true; the OR operator '||', which returns true if at least one operand is true; and the NOT operator '!', which inverts the boolean value of its operand. These operators help in controlling the flow of execution based on multiple conditions .

The if-else statement in programming facilitates decision-making by evaluating a condition; if the condition is true, a specific block of code is executed, otherwise, the alternative block (else) is executed. The execution flow begins by evaluating the expression in the if condition. If true, it immediately executes the code within the if block. If false, it skips the if block and executes the code inside the else block, effectively dictating alternate execution paths based on conditions .

You might also like