1. JAMES KILONZO 19/03722
BBIT(YEAR 1 SEM2) Town campus
PROGRAMMING CAT
Q1.
a) Structured programming is an approach to writing programs thatare easier
to read, test, debug, and modify.
b) C is a portable language because it is not made for a particular platform
hence code written in c can be compatible with all machines. It is also
efficient becauseof availability of efficient compilers.
c)
i. The processor directive is included in a programthat begins with the
character #, which them different froma typical sourcecode text.
ii. Declaration is a statement describing an identifier, such as the name
a variable or a function.
iii. A Function is a group of statement that together performs a test. A
function declaration tells the compilers about a functionโs name,
return type, and parameters.
iv. An expression is a combination of one or more constants, variable,
operators and functions that the programming language interprets
together with a computer to produceanother value.
v. A comment is a programmerโs readableexplanation or a notation in
the sourcecode of a computer program. They are added with a
purposemaking of the sourcecode easier for humans to understand.
d)
๏ c keywords arepredefined, reserved words used in programming
that have special meanings to compiler. They are partof syntaxand
they cannot be used as identifier
Q2.
a. Array variableholds multiple values whereas simple variable holds a single
value.
b. Data type example size
i. Integer e.g. 6,8,10 2bytes
2. ii. Float e.g. 12.3,66.9,7.8 4bytes
iii. Character eg.97(in ASCII) 1byte
Double e.g. 234.4567 8bytes
c.
a) A symbolic constantis an identifier that is replaced by replacement text by
a processor beforethe programis compiled. it involves the useof #define.
b) Itis easier to manage programs
Easy to debug errors
d. A storageclass represents the visibility and a location of a variable. It
describes the features of a variableand how it is stored
i. Static - it is a local variablewhich is capable of returning a value even
when control is transferred to the function call.
ii. Register -used to storevariables.
iii. Auto -is a default storageclass for local variable and can only be used
with functions.
Q3
a) A structureis a user defined data type in c language which allows us to
combine data of different types together.
b) In
Q4
a.
1. Programdesign
Itis a foundation for good program.
3. Programdesign is concerned with development and strategy.
Itinvolves 4 stages:
i. Problem analysis
ii. Outlining the programstructure
iii. Algorithm development
iv. Problem analysis
2. Programcoding
Itshould be readable and simple to understand.
Elements in coding include:
i. Internaldocumentation
ii. Construction of statements
iii. Generality of program
iv. Input/outputformats
3. Programtesting
This is the process of reviewing and executing a programwith the intent of
detecting errors.
Testing should include necessary steps to detect all possibleerrors in a
program.
Itincludes 2 stages:
a) Human testing
b) Computer based testing
b. I) Linking is necessary to compile only those sources files that have changed
for the rest, the objectfiles that are sufficient input for the linker.
ii) because of the errors that are generated while executing the programs.
c. To check wherehe has written the else statement where it should not have
been written. He should also check wherehe has forgotten to put a
semicolon at the end of the statement.
Q5.
a)
4. i. Avoid repetition of codes.
Reduces chances of errors.
Modifying of a programis easier.
Clear programlogic
ii. Function prototypeis a declaration of a function that specifies the
functionโs name and type of signature.
b)
#include<stdio.h>
Intmax(int a, int b);
Intmain ()
{
Inta, b;
Printf(โenter the firstand second number:nโ);
Scanf(โ%d%dโ,&p, &w);
Greater_ num= max(a, b)
Printf(โthelarger value is n%dโ, greater _num);
Return 0;
}
int max(int a, int b)
{
Intvalue;
If(a>b)
{
Value=a;
}
Else
Value =b;
Return value;
}
c)
A function is created which multi plays individual numbers together and
the function is called into the main functions whereit passes its
variables to count.
5. So that when countis 1, the number multi plays itself due to the
variables passed into the main function then the productis displayed on
the screen using printf function and each number is printed on a new
line
Count is increased by one and the process continues up to the level
wherecount is greater than five
Hence the output will be
4
9
16
25
36
49
64
81
100
Q6.
Q7.
Q8.
A.
1) Arithmetic examples addition (+), subtraction (-), division
2) Assignment operator (=) e.g. a=3, x=y, pi=3.142
3) Relational operator e.g. less than (<), greater than (>)
4) Logical operator (&&)-logicalAND, logical OR
B.