Nick Cat I - Structured Programming
Nick Cat I - Structured Programming
.Source code is the original, human-readable programming instructions that a programmer writes to
create a program or application. It is written in a high-level programming language, such as Java, Python,
or C++, and is used to instruct a computer on how to perform specific tasks. On the other hand, object
code is the machine-readable version of the source code, which has been translated into a lower-level
language that a computer can understand and execute. Object code is specific to the computer
architecture and operating system, and is used to create an executable program that can be run on a
computer.
Pseudo code is a way of representing an algorithm or program in a human-readable form that is not
specific to any programming language. It uses natural language-like statements to describe the steps and
logic of a program, making it easier for programmers and non-programmers alike to understand and
analyze the process. Pseudo code is often used as a first step in the programming process, before the
actual implementation in a specific programming language.
B) Describe any three types of errors in C giving an example in each case (3marks)
(i) Syntax Errors: These occur when the code violates the syntax rules of the C programming language.
For example, if you forget to close a parenthesis or use the wrong keyword, it can result in a syntax error.
(ii) Logical Errors: These occur when the code does not produce the expected output due to a logical
mistake. For example, if you write a program to calculate the sum of two numbers but forget to add the
second number, it will result in a logical error.
(iii) Runtime Errors: These occur when the program encounters an error while it is running. For example,
if you try a number by zero, it will result in a runtime error.
C)Write a program that calculates the area and the perimeter of a rectangle given that the
length and the width are entered from the keyboard.The results should be outputted on the screen.
#include
#include
int main() {
scanf("%f", &length);
scanf("%f", &width);
return 0;
(i)Correctness: A good algorithm should produce the correct output for any valid input. It should follow
the specified rules and logic to solve the problem.
(i) Efficiency: A good algorithm should be efficient in terms of time and space complexity. It should use
the minimum number of resources required to solve the problem.
(iii) Simplicity: A good algorithm should be simple and easy to understand. It should be written in a clear
and concise manner, with minimal unnecessary complexity.
(iv)Readability: A good algorithm should be readable and maintainable. It should be written in a way that
makes it easy for others to understand and modify the code.
E) Write a program that calculates the area and circumference of a circle given the radius of the
circle is of float data type and is entered from the keyboard.PI is given a 3.4.The results should be output
on the screen.
#include
#include
int main() {
scanf("%f", &radius);
circumference = 2 * PI * radius;