STRUCTURED PROGRAMMING WITH C - CRASH COURSE CSC 201
STRUCTURED PROGRAMMING WITH C - CRASH COURSE CSC 201
https://vicololawade.com
CSC 201
- VICOL OLAWADE
STRUCTURED
PROGRAMMING
FOR MORE INQUIRIES
P a g e 1 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
AUTHOR’S INTRODUCTION
Author’s Aim
I am Vicol Olawade. A Computer Science student of the 2019/20 set. The
main purpose for this foundation is to help students conveniently learn to code.
And this can only be achieved if students have a very solid foundation in the field
of programming, as most of the students this manual would be useful for are
those offering STRUCTURED PROGRAMMING or its Introduction in the
university .In this regard, its very inconvenient learning to code if you’re being
taught at the same time with others because this won’t give individuals so much
time to learn and practise what have been taught. This foundation provides you
with materials and videos that can help you conveniently learn and understand
this course easily at your own pace.
Learning programming in generally sequential, meaning you take a step at
a time and it also involves practising things you have learnt over a period of time.
I understand that not all students can learn something once they are taught once,
and I also understand that not all students learn when others learn, meaning
some learn better at night than they do in the day. Therefore, this foundation
strongly lies on providing each students quality tutorial that they can learn from at
their own pace.
The YouTube video tutorial is employed because I personally don’t want to
gather you all and coordinate a tutorial for a large amount of students that would
in-turn not be beneficial to you all. Instead, I will frequently drop video tutorials on
a YouTube channel so that you can all download and learn from any day, any
time and any where. With these tools, I believe we can all learn and understand
this course .
Currently, this course is a 3Unit course in the Osun State University
Campus, which means having a good grade in this course does a good job in
boosting your GP for that semester, and that is my AIM.
I remain Vicol Olawade, you can get to contact me by visiting my website
and you can also follow up the tutorials there too…
I WISH YOU SUCCESS IN ADVANCE!
P a g e 2 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
TABLE OF CONTENTS
Table of Contents
CSC 201.............................................................................................................................1
AUTHOR'S INTRODUCTION....................................................................................................................................2
AUTHOR'S AIM.................................................................................................................2
1.0 CSc 201 Introduction..........................................................................................................................................4
P a g e 3 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
ii. Selection: This has to do with decision making where the program is
given a condition and and makes several decisions where the condition
us true or false.
iii. Repetition/Looping: This also deals with decision making where the
program executes a block of codes for as long as the given condition is
true.
It is easy to learn.
P a g e 4 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
CHARACTERISTICS:
APPLICATIONS:
P a g e 6 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
LINK SECTION: This is a section for declaring, linking and calling all
header files & libraries (such as #include <stdio.h>) used in a program.
SUB PROGRAM SECTION: All user defined functions are defined in this
section.
P a g e 7 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
+-*/=%&#!?^“’|<>()[]{} :;.,~@!
P a g e 8 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
Declaration: Declaration is the process of defining the name and data type
of a variable before its usage; In Programming, a declaration determines
the name and data type of a variable or a function.
P a g e 9 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
WHILE
P a g e 10 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
P a g e 11 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
Example
Operator Description
(A=10;B=5)
P a g e 12 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
Example
Operator Description
(A=10;B=5)
P a g e 13 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
P a g e 14 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
P a g e 15 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
P a g e 16 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
All arrays have 0 as the index of their first element which is also called the
base index and the last index of an array will be total size of the array
minus 1.
To declare an array in C:
To Initialize an array in C:
P a g e 17 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
You can divide up your code into several functions. Dividing your code into
different functions is up to you, but logically the division is such that each
function performs a specific task. Dividing your codes into functions helps
to reduce the length of your code and allows you to reuse and perform a
task over and over again without writing extensive amount of codes.
P a g e 18 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
Defining a function in C:
The general form of a function definition in C programming language is as follows
→ Function Name − This is the actual name of the function. The function
name and the parameter list together constitute the function signature.
Example of a function in C:
Given below is the source code for a function called max(). This function takes
two parameters num1 and num2 and returns the maximum value between the two:
P a g e 19 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
return result;
}
Function Declarations in C:
A function declaration tells the compiler about a function name and how to call
the function. The actual body of the function can be defined separately. A function
declaration has the following parts:
Calling a Function in C:
While creating a C function, you give a definition of what the function has to do.
To use a function, you will have to call that function to perform the defined task.
To call a function, you simply need to pass the required parameters along with
the function name(if parameters exists), and if the function returns a value, then you can
store the returned value. For example: max(14,5) //should return 14 since num1(14) is
greater than num2(5).
P a g e 20 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
if(condition) {
// Statements to execute if
// condition is true
}
if(condition) {
// Executes this block if
// condition is true
} else {
// Executes this block if
// condition is false
}
P a g e 21 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
if(condition) {
// Executes this block if
// condition is true
} else if (condition2) {
// Executes this block if
// condition2 is true
} else if (condition3) {
// Executes this block if
// condition3 is true
} else {
// Executes this block if
//all conditions are false
}
switch (n) {
case 1: // code to be executed if n = 1;
break;
case 2: // code to be executed if n = 2;
break;
default: // code to be executed if n doesn't match any cases
}
P a g e 22 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
LOOPS IN C LANGUAGE
A loop is a block of code that will repeat over and over again. Loops in
programming come into use when we need to repeatedly execute a block
of statements. For example: Suppose we want to print “I am Vicol
Olawade” 40 times. Rather than typing printf(“I am Vicol Olawade”); on 40
separate lines in our program, we can create a loop that tells the computer
to print “I am Vicol Olawade” multiple times and stop once it prints the 40th
line. These stated above are basically what loops are for. We have 3 types
of loops in C Language, they are:
For loop: A for loop is a repetition control structure which allows us to write
a loop that is executed a specific number of times. The loop enables us to
perform n number of steps together in one line. For example:
P a g e 23 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
While loop: While loops are used in situations where we do not know the
exact number of iterations of loop beforehand. The loop execution is
terminated on the basis of test condition. For example:
int i = 1;
while (i < 6) {
printf( "Hello World\n");
// update expression
i++;
}
In the while loop above, Our program would keep printing Hello World repeatedly for 5
times and would terminate at the 6th time because the condition will no longer be valid at
the 6th time since i(6) is not greater than 6.
// loop body
printf( "Hello World\n");
// update expression
i++;
} while (i < 1); // test expression
In the above program, the test condition (i<1) evaluates to false because 2 is not less
than 1 but this program will still print out a line of Hello World.
While loop checks the condition first and then executes the statement(s),
whereas do while loop will execute the statement(s) at least once, then the
condition is checked.
While loop statement(s) is executed zero times if the condition is false
whereas do while statement is executed at least once.
P a g e 24 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
Errors are the problems or the faults that occur in the program, which
makes the behavior of the program abnormal, and experienced developers
can also make these faults. Programming errors are also known as the
bugs or faults, and the process of removing these bugs is known as
debugging.
P a g e 25 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
5) SEMANTIC ERROR: Semantic errors are the errors that occurred when
the statements are not understandable by the compiler. The following
can be the cases for the semantic error:
d) Array index out of bound. i.e int a[10];a[10] = 13; //This will produce
an error because the size of the array is 10 and therefore, its
indexing should end at 9 instead of 10.
P a g e 26 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
User defined Functions: These functions are designed by the user to their
own taste when they are writing any program. To perform such functions,
the user have to define the proper definition of the function.
P a g e 27 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
P a g e 28 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
getchar: The getchar function is part of the <stdio. h> header file in C. It is
used when single character input is required from the user.
USEFULNESS OF FUNCTIONS
By using functions, we can avoid rewriting same code over and over
again in a program.
We can call C functions any number of times in a program and from any
place in a program.
P a g e 29 | 30
tutorials.vicololawade.com
STRUCTURED PROGRAMMING WITH C
A variable name can ONLY start with an alphabet and underscore only.
It can’t start with a digit.
A variable name must not be any reserved word or keyword, e.g. int,
goto , etc.
P a g e 30 | 30
tutorials.vicololawade.com