0% found this document useful (0 votes)
14 views

CMP201 Lecture Material

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)
14 views

CMP201 Lecture Material

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
You are on page 1/ 22

AL-HIKMAH UNIVERSITY, ILORIN, NIGERIA

Adeta Road, Adewole Housing Estate, P.M.B. 1601, Ilorin


…..learning for wisdom and morality…..
Lecture Material on CMP 201 (Computer Programming I)

Prepared by: OYELAKIN, A. Moruff


Course Title: Computer Programming I
Course Code: CMP 201
Course Credit: 03

Course Description
Introduction to problem solving, problem solving methods: algorithm development and flowcharting,
programming language concepts. Designing, coding, debugging and documenting programs using
techniques of a good programming language style, Programming examples and solutions.
Note: The programming language to be used in teaching the course is C Programming Language.

Learning Objectives
At the completion of this e-note, it s expected that learners will achieve the following:

1. Understand the basic concepts of computer programming


2. Acquire the necessary teaching skills on problem solving techniques: Algorithm Design and
Flowcharting
3. Exhibit mastery of techniques for writing good programs using C language
4. Be able to write small-size programs using C programming Language

Introduction to Problem Solving


As a beginner in programming, a good mastery of problem solving is required. For you to have a
good start, I want to advise that you try to master some of the basic concepts that I will be

introducing first and then establish relationship between them and subsequent topics/terms. Now, let’s
start with Problem Solving as a topic.

Problem solving is an integral part of Computer Science. Computer is used as a problem solving
tool in both public and private organizations. This statement is a testimony to the rate at which computer
and ICT solutions are used for driving services and operations of government and private establishments
in Nigeria and beyond. From different sectors of the economy, computers are being put to use. They are
used for manufacturing, educating, researching, distributing, and increasing productivity.

While we want to develop a software application, set up a network, troubleshoot a computer problem
(hardware or software) we engage n problem solving. The problem solver is expected to make use of
1
some skills and techniques while solving problems.

Problem Solving in Software Development


In the area of modeling and developing an application (desktop, mobile or server-based), we make
use of problem solving skills and tools. This is because such a task requires some approaches. Some of
the tools used include: Algorithm, Flowchart, Unified Modeling Language (UML), Decision tables and so
on. A problem solver thinks critically. A problem solver should be able to think critically on problem he
intends solving. He is expected to think out of the box in the process of getting a solution provided to an
issue. It is expected that a problem solve able to identify the possible approaches for providing solution to
the problem at hand.

Note: In the context of this course, only Algorithm and Flowchart will be covered at this introductory
level

While developing a program (software), there are stages that the software product (program) must
pass through. The stages are generally called Software Development Life Cycle (SDLC). Depending on
the software development methodology being used, a programmer may need to iterate some of these
stages. For instance, if a programmer is able to conceptualize a solution to a given problem, he may need
to revisit the different stages of the SDLC after testing the solution. If the solution fails to meet the
expected expectations of the client/user, the first set of processes may need to be carried out once more.

The phases of Software Development Life Cycle are:


Problem Definition/User Requirement Analysis Program
Design
Program coding/System coding Program
Testing and Debugging Program/System
Implementation System Evaluation and
Maintenance

Algorithm/Flowchart as Problem Solving Tools

While providing solutions to a wide range of IT problems, problem solving tools can be used. Algorithm
and Flowchart are being introduced herein as problem solving tools that can help drive varying solutions.

Algorithm

2
An algorithm can be defined as the step-by-step procedure for solving a given problem. It clearly spells
out how a solution to a particular problem is achieved. It is equally regarded as sequence of steps that
have to be followed for solving a given problem or performing a given task.
Irrespective of a programming problem to be solved in computing, it is expected that the programmer is
able to identify the best algorithmic approach to be used.

Characteristics of a good Algorithm


A good algorithm must be exact in the process of providing solutions to the problem
A good algorithm must not be ambiguous. That is, the algorithm must be clear enough.
A good algorithm must be finite. This statement means that a good algorithm must have a beginning and
an end. It must not run indefinitely.

A good algorithm is expected to have a clearly defined set of inputs

It is also expected to have matching set of outputs

Example of Algorithm in solving a problem


//This is an algorithm to compute the area of a circle

Step I:Start
Step II:Initialise Pi=3.142
Step III:Enter radius of the circle
Step IV: Compute Area=Pie * square of radius

Step V: Print Area


Step VI: Stop

If you look closely at the above algorithm, you will discover that the various steps that are required for
finding the area of a circle are listed in chronological order. This is made possible

because the formula for finding area of a circle is understood and the various components are well
utilized.

Supposing we have another problem that requires that we draw an algorithm that can accept and display
the personal details of a lecturer in Al-Hikmah University, we may provide the following solution:
//This is an algorithm to accept and display details of a lecturer Step I:
Start
Step II: Accept StaffNo

3
Step III:Accept Surname
Step IV: Accept Firstname
Step V: Accept MiddleName
Step VI: Accept Faculty
Step VII: Accept Department
Step VIII: Accept Gender
Step IX: Print all the accepted values in step II to VIII Step
X; Stop

Flowchart

A flowchart is the pictorial representation of an algorithm. That is a flowchart refers to as the diagrammatic
representation of steps followed in solving a given problem.
The flowchart symbols include:
Terminal Symbol-This is the symbol that is used to indicate the beginning and ending of a flowchart
Start

Processing Symbol-This is the symbol that is used to denote processing and computational activities.

Calculate Total

Flow Arrow-This is the symbol that is used to indicate the direction in which a particular operations is
going.

Decision Symbol-This is the flowchart symbol that is used while making decision.

Input and Output Symbol-This is the kind of symbol that is used for feeding the computers with the set
of needed inputs. The symbol is equally used for generating outputs.

4
Connector-This is used to join a flowchart diagram from one page to another. It should be properly
labeled so as to avoid confusing the user of the diagram.

Note: It has to be pointed out that these symbols are used together to draw flowchart depending on the
problem at hand.

In order to give you a solid foundation in flowcharting, I will like to also provide an example. Lets refer
to the first example on algorithm. Each time you are to draw a flowchart; you must be able to either
sketch the algorithm on paper or having the steps involved in arriving at the algorithm in your head. What
is then left is to use the suitable flowchart symbol to represent the different stages of the algorithm.
The flowchart symbol on the problem mentioned is as shown below. I want to advise that you take time
to peruse the instructions herein and master the various examples so that you can understand better.
Examples on Flowchart Design
(i) Design a flowchart that can accept the matric number, name and score of a student in two courses
and then display the details.
Solution
Start

Accept Matric No

Accept Name

Accept Scores in Course A and


Course B

Print all the details

Stop

(ii) Design and a flowchart that can be used to compute the area of a circle

Solution
Start

Input the radius

5
Initialize Pi=3.14

Compute Area of a Circle

Stop

Programming Language Concepts


To understand programming languages better, it may be necessary to have mastery of some of the basic
concepts. The list of programming language concepts is numerous. Some of them are:

Program
Syntax
Syntax Error

Translator (Compiler, Interpreter and Assembler)

Logical Error
Loop
Data Types
Looping
Identifier-this can be a variable name, a function name and so on.
Programming/Computer Programming
Data Descriptor (%d,%f,%c e.t.c)
Constant
Control Structures
Program logic
Function (In-built function, user-defined function) and many others.

Let me use this opportunity to remind you that there is a need to have a good understanding of these concepts
before you can write meaning program in C.
The section below is used to briefly explain some of the concepts before we go into programming, proper.

(i) What is a program?


A program is the set of instructions that tells the computer system how to perform a given task. Every
program is written with the use of a programming language or a combination of programming languages.
Let me use this opportunity to remind you that the choice language for teaching this course is C. So, we

6
will be focusing on introducing you to the syntaxes of C as a programming language.

(ii) What are data types?


Data Types- a data type describes the kinds of data that can be entered into the computer system at a time.
Two categories of data type are supported in C language. They are:

a. Simple data type (e.g. integer, character, float, double, long integer e.t.c)

and

b. Composite/Complex Data Type (e.g Array, Structures, String, Enumerated, Union e.t.c).
Note: It is expected that a programmer determines and use the most appropriate data type in a particular
program before proceeding to writing the codes.

This course being an introductory course considers only simple data types in some of the examples and
exercises..

In C language, for each of the data that is to be handled, a data descriptor should be used. The data
descriptor, as it name implies-gives the description of the data that the user can supply from an input
device into the c program.

(iii) Computer Programming or Programming is the act of coding instructions for computer to
carry out. Providing solution to a problem is achieved with the use of suitable programming
language. The choice of a programming language for a given problem depends on a number of
factors. These factors include:

the programming needs,


the domain of the problem (education, enterprise, hospitality, banking, e.t.c) the
ease of use of the programming language
the level of education/technical expertise of the programmer among
others.
(iv) Levels of Programming Language-There are three levels of programming languages. They are:
a. Machine Language;
b. Low Level Language (LLL) or Assembly Language and;

c. High Level language (HLL).


Examples of High Level Languages are: C++, C. PASCAL, Ada, FORTRAN, Python, Java, BASIC,
Smalltalk, Delphi, and so on.
More so, programming languages can be classified into Imperative, Functional, Structured,

7
Object Oriented programming languages and so on. Object Oriented Programming is a programming
method that combines data and instructions for processing that data into a self- sufficient ‘object’ that can
be used within a program or in other programs. In OOP, Objects are modeled on real world entities. This
enables modeling complex systems of real world into manageable software solutions.
These languages are written using human language and have their well defined syntaxes. A
programmer in whatever level has to obey the syntax of the chosen language he/she wants to use to
develop the targeted applications/softwares. High Level Languages use language translator to be executed
on a computer/machine. These translators are either interpreter or compiler.

Programming in C Language

Brief History
C Programming Language is a Structured programming language that can be used for developing varying
mathematical and scientific applications. C was developed by Dennis Ritchie at AT&T Bell Labs, the
USA in early 1970s. As a High level programming language, C has support for various mathematical and
scientific functions. The language makes use of compiler. These compilers are from various vendors and
of different versions. Examples of such C compilers include: Tiney C, Netbeans C, GNU C, Open64,
Smaller C, Borland C and so on.
C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to
develop the UNIX operating system at Bell Labs. C has now become a widely used professional language
for various reasons:
 C is Easy to learn
 It is a Structured Programming language
 It produces efficient programs
 It can handle low-level activities
 It can be compiled on a variety of computer platforms
While programming in C, there are a lot of compiler types that are available. They are: Turbo C, Open64,
Tiny C, Small C, Borland C, Netbeans C, Code Blocks and many others.
Note: While writing programs in C language, efforts should be made to have a good understanding of the
syntaxes of the language. Syntax simply means the set of rules that have to be followed while writing
valid program statement in the language. When the syntax of the language is violated, we have what is
called syntax error.
The choice programming language is C and the compiler being used to run the codes in this course for
demonstration purposes is Netbeans C.
It has to be mentioned that Netbeans is an IDE that support various programming languages (Java, C, C+
+, PhP) depending on the one that is installed on the machine being used for the programming activities.
8
For you to write valid program using C langu, you are expected to master the syntaxes of the language.
Programming is not about cramming. Having mastered the syntaxes you have to practice and use your
experience to solve programming problems.

What C Language was being used for:

In the beginning, C was used for developing system applications such as:

i. Database Systems
ii. Language Interpreters
iii. Compilers and Assemblers
iv. Operating Systems
v. Network Drivers
vi. Word Processors

C as a Compiled Language

C is a compiled language. This statement means that C source code is converted to equivalent machine code all
at once. A compiler is a translator that compiles the program and converts it into the object file which is
machine readable. After the compilation process, the linker will combine different object files and creates a
single executable file to run the program. The following diagram shows the execution of a 'C' program

Figure 1: Compilation Process of C Language

Nowadays, various compilers are available online, and you can download and use any of those compilers.

For the purpose of this course, Netbeans C compiler is recommended. You can download this compiler from
www.netbeans.org. After the download, you can then install the application on your system. Each time
you write a program (as a beginner) in your programming notebook, you can then go ahead and type
in the codes into the netbeans environment, run and execute them in order to obtain the output.

9
It has to be pointed out that C is case sensitive and you should make sure that keywords and variables
are correctly typed and used. The meaning of case sensitivity of C language is that it differentiates
between upper case letters and lower case letters (whether keywords or identifiers).

Note: You are expected to download the version (32 bit or 64bit) that is compatible to the architecture of
your system.

Keywords in C Programming Language


A keyword refers to as the word that has predefined meaning to the C compiler. Some good examples of
keywords in C include: include, int, float, double, scanf, for, while, do, switch, main, printf, char,bool,short,
while, do and many others.
Note: C is a case sensitive programming language. This statement means that C differentiates between
upper case letter and lower case letter. Also, every C program must have a main function. There is also
what we called pre processing directive. Some of the processing directives used in a C program are:
#include, #define and so on.
Note: To be able to program effectively in any programming language, it is required that the programmer
masters the syntaxes of such language and then develop the ability for reasoning based on the required
program logic of each problem. Programmer does not need to cram anything as problem varies.
Choosing Variable Names in C
In C programming language, a variable or variable name is used as the storage location for data.
Depending on the data type that we want to use in a program, we declare the variable as such.
To have a valid variable name in C, one is expected to have a mastery of the rules for declaring the
variables.
Some of such rules include:

i. A valid variable name in C should start with an alphabet or letter InitialValue,Num,Value


ii. A variable name in C can be a mixture of alphabet or number (but must not start with the
number) e.g. Traveller45,T78,A5,Value34,num23,number892
iii. A valid variable name must not be C keyword e.g StaffID,StayPay,ItemNo,AssetCode
iv. A valid variable name must not contain blank space. E.g StudentAge,MatNumber
v. A valid variable name may contain alphabets, numbers and/or with underscore (_) e.g. sum_score

For instance the following are valid variable names because they obey one or all the rules
mentioned above:
(i) sum (ii) studentscore (iii)Totalsalary23 (iv) Manager_Pay (v) StudentAdd4 e.t.c

10
The following variable names are not valid
(i) 34Name (ii) Sum total (iii) President name* (iv)printf (v) getchar (vi) N89}

Escape Sequence in C Language

Escape sequences are used in the programming languages C and C++, and their design was copied in
many other languages such as Java and C#. An escape sequence is a sequence of characters that does not
represent itself when used inside a character or string literal, but is translated into another character or a
sequence of characters that may be difficult or impossible to represent directly. In C, all escape sequences
consist of two or more characters, the first of which is the backslash, \ (called the "Escape character"); the
remaining characters determine the interpretation of the escape sequence. For example, \n is an escape
sequence that denotes a newline character.

Table of escape sequences

The following escape sequences are defined in standard C. This table also shows the values they map to in
ASCII. However, these escape sequences can be used on any system with a C compiler, and may map to
different values if the system does not use a character encoding based on ASCII.

Escape sequence Hex value in ASCII Character represented


\a 07 Alert (Beep, Bell)
\b 08 Backspace
\enote 1 1B Escape character
\f 0C Formfeed Page Break
\n 0A Newline (Line Feed)
\r 0D Carriage Return
\t 09 Horizontal Tab
\v 0B Vertical Tab
\\ 5C Backslash
\' 27 Apostrophe or single quotation mark
\" 22 Double quotation mark

Note: Some of the ways to use these escape sequences go beyond this course. We are only introducing
them for better references.

Understanding Looping Structures in C Language


C, as a programming language, supports a wide range of loop structures. These loop structures are used to
carry out some set of programming tasks in repeated manner. The popular among them are FOR LOOP, DO
WHILE and WHILE DO.

11
In this course, emphasis will be on FOR LOOP. Mention will also be made of DO WHILE LOOP and
WHILE DO LOOP. In future programming course named, CMP301, you will be exposed to some other
areas.

Like any other program constructs, these loops have their syntax which must be adequately mastered and
put to use for proper practical mastery.
What is Looping?
Looping can be defined as the process of performing certain segment of a program n a repeated manner until
the specified condition is met. The loop allows programmer to write program codes that are able to run
repeatedly.

Syntax of FOR LOOP in C


This is the simplest and mostly used loop statement for beginners. It has
the general syntax:
The syntax of a FOR LOOP in a C Program is as follows:

FOR (index variable=initial condition, variable increment or decrement)


{
Program codes
}
Examples: (i)
int k;
for (k=1;k<=34;k++)
{
Program codes
}
This code runs repeatedly until the specified value of 34 is reached. The index variable is incremented by
1,one at a time.

(ii) int j;
for (j=150;K>=5;j--)
{
Program codes;
}

This codes run repeatedly until the specified value of 5 is reached. The index variable is decremented by 1,
12
from 150 till it reaches 5.
THE WHILE LOOP /WHILE Statement
The while statement continually executes a block of statements while a particular condition is true. Its
syntax can be expressed as:
while (expression)
{
//Program statement(s)
}
The while statement evaluates expression, which must return a boolean value. If the expression evaluates
to true, the while statement executes the statement(s) in the while block. The while statement continues
testing the expression and executing its block until the expression evaluates to false.
Practical Program Example on While DO LOOP
Use the while statement to print the values from 1 through 40.
Solution
The solution to the programming problem can be accomplished as in the following While DO Example
program:
#include <stdio.h>

int man ()
{
int count = 1;
while (count < 11)
{ printf(“%d " +
count); count++;
}
}

Syntax of a DO WHILE LOOP


The C programming language also provides a do-while statement, which can be expressed as follows:
do {
statement(s)
} while (expression);
The difference between do-while and while is that do-while evaluates its expression at the bottom of the
loop instead of the top. Therefore, the statements within the do block are always executed at least once, as
shown in the following program that uses Do While Loop:
13
int main() {
int count = 1;
do {
printf("%d " + count);
count++;
} while (count < 11);
}

Note: The program segment will print the value of variable count while count is less than 11.

Some Programming Examples and Solutions


Introduction
As a way to develop some valid foundations in the students, it is my honest wish to provide some
practical and theoretical questions on C programming. To facilitate this foundation, the answers to such
questions are provided herein. Students are expected to have studied the material, ask questions during
lectures, practice some of the code examples on their systems and then try out the questions on their own
before looking through the answers.
Question: Write a C program that can accept ten integer values and then compute their average.
Solution
#include <stdio.h>
void main()
{
int i,n,sum=0;
float avg;
printf("Input the 10 numbers : \n");
for (i=1;i<=10;i++)
{
printf("Number-%d :",i);

scanf("%d",&n);
sum +=n;
}
avg=sum/10.0;
printf("The sum of 10 no is : %d\nThe Average is : %f\n",sum,avg);

Question
Write a C program to convert a temperature given in celcius scale to fahrenheit.
Solution

14
**
* C program to convert temperature from degree celsius to fahrenheit
*/

#include <stdio.h>

int main()
{
float celsius, fahrenheit;

/* Input temperature in celsius */


printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);

/* celsius to fahrenheit conversion formula */


fahrenheit = (celsius * 9 / 5) + 32;

printf("%.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit);

return 0;
}

Question 3:
Write a C program to find the power (exponent) of any number.

Solution
/**
* This is a C program to find power of any number.
*/

#include <stdio.h>
#include <math.h> // For this problem use for pow() function

int main()
{
double base, expo, power;

/* Input two numbers from user */


printf("Enter base: ");
scanf("%lf", &base);
printf("Enter exponent: ");
scanf("%lf", &expo);

/* Calculates base^expo */
power = pow(base, expo);
printf("%.2lf ^ %.2lf = %.2lf", base, expo, power);

return 0;
}

Questions and Answers Section

15
This section provides some questions and answers so as to improve the understanding of the learners.
Please take time to read through the questions and the answers. You are expected to practice on your
own.

(1a)List any ten examples of keywords supported by C Programming Language.

(1b)Write a C Program that can add integer values from 450 to 890
(1c)Mention any four primitive data types supported in C Programming Language
(2a) Define translator and mention any two relevant examples
(2b) Write a C program to find the area of a circle given that Area=∏r2

(2c)Define each of the following terms: (i) Algorithm (ii) Flowchart

(3a)Write the syntax of FOR LOOP in C Programming Language

(3b) Copy and complete the table below by establishing the validity of the identifiers or otherwise
S/N Identifier Status Reason
i sumtotal
ii 3Maverage
iii Agestud123
iv switch
v printf
vi EmployeeDetails

(3c)Write a C program that can compute Q given that Q=6T + 15K

(4a)(i) List any three data descriptors used in C Programming?


(ii)Mention any three versions of C Programming Language
(4b) Write a C Program that can accept the scores of a student in four courses, then calculate the average
score of the student in the courses.
(5a) Define each of the following terms:

(i) Compiler
(ii) Logical Error
(iii) Syntax Error
(5b) Write a C Program that can accept scores of a student in ten courses and then compute the average
score. Hint: Use array and a suitable Loop structure to perform the task .

(6a) Explain the term “looping”


16
(6b) Write short notes on preprocessing directive in C. Give at least two examples
(6c) Write a C program that can display the message” Learning at Al-Hikmah University is wonderful”
seventy times with the use of FOR LOOP

Solutions to the Sample Questions


Question One
1a. Examples of keywords in C Programming language are:
Scanf,printf,void,main,int,double,float,switch,return,long,char,string and so on

1b.
/*A C program to add integer values from 12 to 270 */
5maarks
#include <stdio.h>
int main ()
{
int sum=0;
int j;
for (j=12;j<=270;j++)
{
sum=sum+j;
}
printf(sum);
return 0;
}

1c. The primitive data types supported in C Programming language include: Integer
Float Double
Long Integer
Character and so on

Solution to Question Two


2a. A translator is regarded as the software that converts a program written in High Level Language or
Low Level Language to Machine understandable format. Good examples of translator include:
Assembler (For low level language) Compiler
and

17
Interpreter

2b. /*A C program to compute the circumference of a circle */


#include<stdio.h>
#include<math.h>
#define pi=3.142;
int main()

float Circumference; float


radius;
scanf(“%d”,&radius);
Circumference=2*pi*radius;
printf(circumference); return
0;
}
2c. (i) Algorithm refers to as the step by step procedure that has to be followed in solving a given problem
or performing a given task.
(ii) Flowchart can be defined as the diagrammatic representation of algorithm.

Solution to Question Three


3a. The syntax of a FOR LOOP in a C Program is as follows:

FOR (index variable=initial;condition;index variable increment or decrement)


{
Program codes
}
Note: The increment or decrement of index variable depends largely on the way the problem at hand has
to work.
Adequate explanation and examples will be given during the class lectures. Examples are equally given
below.
Examples: (i)
int k;
For (k=1;k<=34;k++)
{
Program codes
}
18
(ii) int j;
For (j=150;K>=5;j--}
{
Program codes;
}

3b.

S/N Identifier Status Reason


I Sumtotal Valid It observes variable
formation rules
Ii 3Maverage Invalid It begins with digit
Iii Agestud123 Valid It observes variable
formation rules
iv printf invalid It is a keyword

3c. /* Given that Q=6T + 15K, this is a C program to find Q */ #include


<stdio.h>
int main ()
{
int Q,T,K;
scanf(“%d”,&T);
scanf(“%d”,&K);
Q=6*T+15*K;
printf(“%d”,&Q);
return 0;
}
Solution to Question Four
4ai. The data descriptors used in C Programming Language include:
%d for integer
%c for character
%f for floating point numbers
19
%l for long integer

4a.ii Some examples of versions of C Programming Language are: Open64,GNU C,


Turbo C, Quick C, Simple C, Tiny C, Open WatCom and so on

4b. /*A C Program to compute the average score of a student in four courses */ #
include<stdio.h>
int main()
{
int score1,score2,score3,score4; int
scoresum,averagescore;
scanf(“%d %d %d %d”, &score1, &score2,&score3,&score4);
scoresum=score+score2+score3+score4; averagescore=scoresum/4;
printf(“%d”,averagescore);
return 0:
}

Solution to Question Five


5a. (i) A compiler is the kind of program translator that converts a program written in High Level
language to machine language, all at once.
(ii) A logical error is the kind of error that occurs when a program runs but fails to perform the desired
operation for which it is designed
(iii) Syntax error-This is the kind of error that occurs when the syntax of a programming language is
violated. 6marks

/* This is a C program to accept ten scores */ #


include <stdio.h>
int main ()
{
int Socre[10];;
int m;
int Sum=0;
int avg;
for(m=1,m<=10,m++)
{

20
scanf(“%d”, Score[m]);
Sum=Sum+Score[m];

Avg=Sum/10;
printf(“%d”,avg);
return 0;
}

Solution to Question Six

6a. The term looping refers to as the process of performing some segment of program statements in a
repeated manner until a certain condition is satisfied. Looping is carried out with the use of loop
statements such as FOR LOOP, Do WHILE LOOP and so on.

6b.
Good examples of preprocessing directives in C are:
#include
#define

6c. /* A C program to display the message about Al-Hikmah University */


#incude <stdio.h>
int main ()
{
int k; for(k=1;k<=70;k++
{
printf(“\nLearning at Al-Hikmah University is wonderful”);
}
return 0;
}

Study Questions
1. Define each of the following terms: (i) Program (ii) Programming (iii) Problem solving
2. Write a C program to find the perimeter of a rectangle given that P=2(L+B) where L and B are length
and Breath respectively.

3. Explain the case sensitivity feature in C Programming Language


4. Why is there a need for commenting in a C Program?
21
5. Design an algorithm and a flowchart to compute the value of T given that T=23M-4G/3 Note:
M and G are input variables.
6. Itemise the stages of Software Development Process/ Software Development Life Cycle
7. What are data descriptors in Programming Language?
8. Write a C program to display integer values from 1250 to 350
9. Write a C program to display the message “Al-Hikmah University is waxing stronger” five hundred
times
10. Comment on the importance of problem solving skills in programming as a student programmer
11. Write a C program to find the roots of a quadratic equation given that ax2+bx+c=0 Hint:
Use Almighty formula for your problem
12. Identify any five flowchart symbols that you know
13. Design an algorithm and a flowchart to accept the staffID, surname, firstname, middlename, department
and age of a staff in XYZ Polytechnic
References

1. Paul Deitel and Harvey Deitel (2010). C How to Program 6th Edition, Pearson Education,
Inc.Upper Saddle River, New Jersey

1. Tim Bailey (2005). An Introduction to the C Programming Language and Software Design

2. Tutorial Point (nd). C Programming Overview retrieved from


https://www.tutorialspoint.com/cprogramming/c_overview.htm

K. Recommended books/Materials /Web Documents

2. Paul Deitel and Harvey Deitel (2010). C How to Program 6th Edition, Pearson Education, Inc.Upper
Saddle River, New Jersey

22

You might also like