Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
581 views

STE Computer Programming Q1 MODULE 8

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
581 views

STE Computer Programming Q1 MODULE 8

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

10

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.

Published by the Department of Education – Regional Office VIII


Regional Director: Ramir B. Uytico EdD, CESO IV
Assistant Regional Director: Arnulfo M. Balane, CESO V

Development Team of the Module


Writers: Francis Stephen R. Villanueva, Oliver B. Jaguines
Language Editors: Roxan D. Apinardo
Content Editors: Rezalyn E. Arrago
Illustrators: Oliver Jaguines
Layout Artist: Name
Management Team:
Rosemarie M. Guino EdD,OIC – Chief, CLMD
Ryan R. Tiu EdD, EPS, CLMD – Science
Joy B. Bihag, EPS, CLMD – LRMS
Jose B. Mondido, Chief, CID
Lutheshane G. Gutierrez, EPS, CID – Science
Francisco Bayon-on. EPS, CID - LRMS

Printed in the Philippines by ________________________

Department of Education –Regional Office VIII

Office Address: Government Center, Candahug, Palo, Leyte

Telefax: 053 - 3233156


E-mail Address: region8@deped.gov.

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.

This module has the following parts and corresponding icons:

This will give you an idea of the skills or


Explore
competencies you are expected to learn in the
module. A brief drill or review to help you link
the current lesson with the previous one. The
new lesson will also be introduced to you in
various ways such as a story, a song, a poem, a
problem opener, an activity, or a situation.

This section provides a brief discussion of the


Learn
lesson. This aims to help you discover and
understand new concepts and skills.

What’s More This comprises activities for independent


practice to solidify your understanding and
skills of the topic. You may check the answers
to the exercises using the Answer Key at the
end of the module.

This includes questions or blank


Apply sentence/paragraph to be filled into process
what you learned from the lesson.

Assess This is a task which aims to evaluate your level


of mastery in achieving the learning
competency.

This contains answers to all activities in the


Answer Key module.

This contains the learner’s reflection. Learners


Reflect
are encouraged to think about the lessons
particularly the parts that went well (they have
understood) and the parts that were weak (they
have difficulty) and write about it briefly.
Learners can share their thoughts and feeling
iv
about the lessons.

At the end of this module you will also find:


References This is a list of all sources used in
developing this module.

The following are some reminders in using this module:

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:

In programming, the basic syntax reflects a programming language's fundamental


laws. It is difficult to write a working code without these rules. Each language has a
set of rules of its own that make up its basic syntax. Naming conventions are a
primary component of basic syntax conventions and differ from language to
language. And in this module, you will learn the basic syntax of a programming and
how to apply these syntaxes in an actual programming.

After going through this module, you are expected to:

Apply the basic syntax of programming language.

Subtask:
1. Identify the basic syntax of programming.
2. Give the importance of syntax in programming.
3.

Q1_STE_Computer Programming_Module 8 Page 1 of 13


Q1_STE_Computer Programming_Module 8 Page 2 of 13
Learn

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.

Basic Syntax of C Programming Language


Now we will concentrate on the syntax and the structure of the program in C. At
this point, we are not going to be addressing any complex software code. This lesson
will therefore assist you to start in a precise way with a basic C program. You’ll be
able to explain each line of code at the end of this lesson.
So, let’s start today’s journey with C Basic Syntax.

Q1_STE_Computer Programming_Module 8 Page 3 of 13


The C basic syntax consists of header files, main function, and program code. This is
the most fundamental structure in the C program. A C program necessarily consists
of the main function because the execution of the program starts from this line.
Without the main function, the program execution does not start. Look at the
example program below:

#include<stdio.h> Header File


int main()
{
Program Code printf("Hello World!\n"); Main Function
return 0;
}

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.

Q1_STE_Computer Programming_Module 8 Page 4 of 13


3. Tokens

The C syntax/program consists of a set of tokens. They may be identifiers,


variables, symbols. We may assume that they are the smallest units in the
program that convey a particular meaning to the compiler. There are 5 types
of tokens in C Language, they are:

 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");

The individual tokens are:


1. printf
2. (
3. "Hello, World! \n"
4. )
5. ;

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.

There are two types of comments:

 Single Line–for a single line comments, symbols // is used before the


comment line.
 Multi-line– symbols used in multi-line comments are, /**/, the statement
of the comment should be enclosed within /* and */.

// This is a single line comment


/* This is a multi-line comment */

Q1_STE_Computer Programming_Module 8 Page 5 of 13


5. Whitespaces

Whitespace is a term that indicate blanks, tabs, characters and comments in


C program. It serves as a division between two elements of a statement that
would help the compiler identify and decide where one elements end and the
next element starts in a statement. For example,

Program statement

Element int num;


Element
Whitespace

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

Semicolons are provided to terminate the statement. A Semicolon indicates


the start and end of statement execution. If the semicolon is not provided, it
will generate “Compilation Error”. For example, the following two statements:

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;

// Asks for user input Single Line


printf("Input: "); Comment
scanf(“%d”, &i);
Semicolon
return 0; after each
} statement
Program codes
enclosed with
curly braces.

Q1_STE_Computer Programming_Module 8 Page 6 of 13


Engage

Activity 1. Identify the different Basic Syntax of C


Programming Language

____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.

ACTIVITY 2: True or False!

INSTRUCTIONS: Write TRUE if the given program statement is correct, otherwise


write FALSE and give the correct code/syntax.
____________________ 1. #include “stdio.h”
____________________ 2. prints(“Hello World”);
____________________ 3. \\ This is a comment
____________________ 4. main(){ }
____________________ 5. int num

Q1_STE_Computer Programming_Module 8 Page 7 of 13


Apply

ACTIVITY 1: Fill in the Blanks!

INSTRUCTIONS: Complete the program given by choosing the correct syntax from
the given choices inside the box.

// stdio.h { return 0 main() /* function()

int return 1 ; math.h : , */ }

1. #include<________>

2. int _____()
3. _
int i;

4. __ The outputs are:


5. 0 1 2 3 4 5 6 7 8 9__

for(i=0;i<10;i++){
6. printf("%d ", i)_
}
7. ________;
8. _

Q1_STE_Computer Programming_Module 8 Page 8 of 13


Assess

I. Multiple Choice. Choose the letter of the best answer. Write the chosen letter on
a separate sheet of paper.

1. Which of the following are included in the C program basic syntax?

a. header files
b. main function
c. program code
d. all of the above

2. Semicolons are provided to terminate the statement. A Semicolon indicates


the start and end of statement execution. If the semicolon is not provided, it
will generate “____________”.

a. This folder is empty


b. unresponsive program
c. system error
d. compilation error

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. ()

4. The following are some of the commonly used header files in C


program except:

a. stdio.h
b. ctype.h
c. limits.h
d. printf

5. The C programming language uses __________ to define blanks, newline


characters and comments.

a. comments
b. whitespaces
c. tokens
d. semicolon

Q1_STE_Computer Programming_Module 8 Page 9 of 13


II. Modified True or False. Write TRUE if the given program statement is correct,
otherwise write FALSE and give the correct code/syntax.

_____________________________ 1. #include <stdio.h>


_____________________________ 2. prints(“Hello World”);

_____________________________ 3. \\ This is a comment

_____________________________ 4. main(){ }

_____________________________ 5. int num

_____________________________ 6. /* This is a multi-line comment*/

_____________________________ 7. \* This is the correct multi-line comment*\

_____________________________ 8. \* This is the real multi-line comment*/

_____________________________ 9. printf(“I love programming”);

_____________________________ 10. Hello12 is a string.

Q1_STE_Computer Programming_Module 8 Page 10 of 13


Reflect

1. What are the parts of the lesson that went well?


___________________________________________________________
___________________________________________________________
___________________________________________________________
__________________________________________________________.

2. What are the parts of the lesson that you have difficulties?
___________________________________________________________
___________________________________________________________
___________________________________________________________
__________________________________________________________.

3. What areas of the topic you need to understand more?


___________________________________________________________
___________________________________________________________
___________________________________________________________
__________________________________________________________.

Q1_STE_Computer Programming_Module 8 Page 11 of 13


Answer Key

Q1_STE_Computer Programming_Module 8 Page 12 of 13


References

[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/

Q1_STE_Computer Programming_Module 8 Page 13 of 13


For inquiries or feedback, please write or call:

Department of Education – Regional Office VIII – Curriculum and Learning


Management Division (CLMD) - Learning Resources Management Section (LRMS)

Government Center, Candahug, Palo, Leyte, 6501

Telefax: (053) 323-3156; 323-3854; 824-4627

Email Address: *region8@deped.gov.ph


*clmd.region8@deped.gov.ph *lrmds.region8@deped.gov.ph

Q1_STE_Computer Programming_Module 8 Page 14 of 13

You might also like