STE Computer Programming Q1 MODULE 8
STE Computer Programming Q1 MODULE 8
Computer
Programming
Quarter I – Module 8:
Basic Syntax of Programming
Computer Programming– Grade 10
Self-Learning Module
First Edition, 2020
Republic Act 8293, section 176 states that: No copyright shall subsist in any work
of the Government of the Philippines. However, prior approval of the government agency or
office wherein the work is created shall be necessary for exploitation of such work for profit.
Such agency or office may, among other things, impose as a condition the payment of
royalties.
Borrowed materials (i.e., songs, stories, poems, pictures, photos, brand names,
trademarks, etc.) included in this module are owned by their respective copyright holders.
Every effort has been exerted to locate and seek permission to use these materials from
their respective copyright owners. The publisher and authors do not represent nor claim
ownership over them.
ii
Introductory Message
This Self-Learning Module (SLM) is prepared so that you, our dear learners,
can continue your studies and learn while at home. Activities, questions,
directions, exercises, and discussions are carefully stated for you to understand
each lesson.
Each SLM is composed of different parts. Each part shall guide you step-by-
step as you discover and understand the lesson prepared for you.
At the end of each module, you need to answer the assessment to self-check your
learning.
Answer keys are provided for each activity and test. We trust that you will be
honest in using these.
In addition to the material in the main text, Notes to the Teacher are also
provided to our facilitators and parents for strategies and reminders on how they
can best help you on your home-based learning.
Please use this module with care. Do not put unnecessary marks on any part
of this SLM. Use a separate sheet of paper in answering the exercises and tests.
Read the instructions carefully before performing each task.
If you have any questions in using this SLM or any difficulty in answering the
tasks in this module, do not hesitate to consult your teacher or facilitator.
Thank you.
iii
For the learner:
Welcome to the Computer Programming Self – Learning Module on the Basic Syntax
of Programming Language.
The hand is one of the most symbolized part of the human body. It is often used to
depict skill, action, and purpose. Through our hands we may learn, create, and
accomplish. Hence, the hand in this learning resource signifies that you as a
learner is capable and empowered to successfully achieve the relevant competencies
and skills at your own pace and time. Your academic success lies in your own
hands!
This module was designed to provide you with fun and meaningful opportunities for
guided and independent learning at your own pace and time. You will be enabled to
process the contents of the learning resource while being an active learner.
1. Use the module with care. Do not put unnecessary mark/s on any part of the
module. Use a separate sheet of paper in answering the exercises.
2. Read the instruction carefully before doing each task.
3. Observe honesty and integrity in doing the tasks and checking your answers.
4. Finish the task at hand before proceeding to the next.
5. Return this module to your teacher/facilitator once you are through with it.
If you encounter any difficulty in answering the tasks in this module, do not
hesitate to consult your teacher or facilitator. Always bear in mind that you are
not alone.
We hope that through this material, you will experience meaningful learning and
gain deep understanding of the relevant competencies. You can do it!
v
Explore
Introduction:
Subtask:
1. Identify the basic syntax of programming.
2. Give the importance of syntax in programming.
3.
Understanding Syntax
Basically, syntax refers to the protocols followed when a program is being written.
To get the desired output set, it is very important to follow proper syntax when
coding. Every programming language has different syntax used in creating a
program but despite being different their functions and outputs are the same. In
this lesson, we will be using C Programming Language.
C Programming Language
C programming, developed in 1972 by Dennis M. Ritchie at the Bell
Telephone Laboratories to create the UNIX operating system, is a general
purpose, procedural, imperative computer programming language.
We have learned the location of these elements from the above C syntax. Now let’s
discuss in detail each aspect of the code above.
1. Header Files
Header files contain a bunch of files that help the user to include the
predefined functions according to his requirements. The header files can be
applied using the preprocessor directive #include.
Syntax:
#include<file> or #include “file”
Some of the commonly used header files in C are as follows:
File Description
stdio.h Input/Output Functions
conio.h Console Input/Output Functions
stdlib.h General Utility Functions
math.h Mathematics Functions
string.h String Functions
ctype.h Character Handling Functions
time.h Date and Time Functions
float.h Limits of Float Types
limits.h Size of Basic Types
Functions to determine the type contained in wide
wctype.h
character data
2. Main Function
The main function is like the main body of the whole programming code. The
execution of the program starts from this line that’s why it is mandatory to
have main function for any C program.
Syntax:
main(){…}
The program codes the user wish to execute should be written inside the
curly braces. Other than that, the program won’t run and will generate an
error.
Keywords- are set of words used for a special purpose in the program.
They are reserved words. Some examples are for, while, switch, break,
goto, etc.
Identifiers/Variables - It is a data item in the program which value can
be changed and thus, it is called variable. They are a combination of
letters and digits.
Constants - Constants are those values that cannot be changed during
program execution.
Punctuators- Punctuators are used for formatting the C program
statements and expressions. Examples for punctuations are: [ ] ( ) { } : ; , =
Operators- There are various operators in C that we use in order
to perform different mathematical operations.
For example, this C statement is composed of five tokens.
printf("Hello, World! \n");
4. Comments
A comment is a simple text that makes the code more descriptive and
readable. You should include comments in your code just to clarify how the
code works. Comments are not a mandatory part of the code; you may add
them according to your convenience.
Program statement
As you can observe, there’s a whitespace between the two elements int and
num. This is to determine the ending of the first element int, and the starting
point of the second element num.
6. Semicolons
int input;
printf(“Hello World”);
Rules in C Program
1. C is a case sensitive language. Most of the program statements are in lower
case.
2. All statements must necessarily terminate with a semicolon.
3. Whitespaces should be provided only between variables and keywords.
#include<stdio.h> Including
Main function int main() header file
must be here. {
int i;
____1. It contains a bunch of files that help the user to include the predefined
functions according to its requirements.
____2. It is a simple text that makes the code more descriptive and readable.
____3. It indicates the start and end of statement execution.
____4. It is like the main body of the whole programming code.
____5. In a C program, ____________ is usually a blank line.
INSTRUCTIONS: Complete the program given by choosing the correct syntax from
the given choices inside the box.
1. #include<________>
2. int _____()
3. _
int i;
for(i=0;i<10;i++){
6. printf("%d ", i)_
}
7. ________;
8. _
I. Multiple Choice. Choose the letter of the best answer. Write the chosen letter on
a separate sheet of paper.
a. header files
b. main function
c. program code
d. all of the above
3. There are two types of comments (Single Line and Multi-line). For a single
line comments, symbols ______ are used before the comment line.
a. //
b. /**/
c. []
d. ()
a. stdio.h
b. ctype.h
c. limits.h
d. printf
a. comments
b. whitespaces
c. tokens
d. semicolon
_____________________________ 4. main(){ }
2. What are the parts of the lesson that you have difficulties?
___________________________________________________________
___________________________________________________________
___________________________________________________________
__________________________________________________________.
[1]
C Programming Tutorials – Simple and Made Easy by Tutorialspoint.com,
https://www.tutorialspoint.com/cprogramming/c_basic_syntax.htm
[2]
https://data-flair.training/blogs/c-basic-syntax-rules/