Programming Module
Programming Module
University
University
it Nueva
of of
in Caceres
Nueva Caceres
aCollege
nurturing
College of
ofEngineering
Engineering andand
Architecture
Architecture
environment.
We champion
excellence
______________________________________
We nurture Dreams Name of Student
We do the right
things right
______________________________________
We are dynamic Instructor
and creative
cea@unc.edu.ph
054-4726100 loc. 121
COPYRIGHT © 2020
UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE
CONTENTS
CONTENTS ............................................................................................................................................................. 2
COURSE DETAILS(TO EDIT) ..................................................................................................................................... 5
WEEK 1: INTRODUCTION TO COMPUTER FUNDAMENTALS .................................................................................... 6
INTRODUCTION ......................................................................................................................................................6
COMPUTER OVERVIEW ............................................................................................................................................7
HISTORY OF THE COMPUTER .....................................................................................................................................8
LABORATORY ACTIVITY NO. 1 .................................................................................................................................13
WEEK 2: HARDWARE AND SOFTWARE ................................................................................................................. 16
INTRODUCTION ....................................................................................................................................................16
HARDWARE & SOFTWARE .....................................................................................................................................16
EVOLUTION OF OPERATING SYSTEM.........................................................................................................................21
PROGRAMMING SOFTWARE AND UPDATES ...............................................................................................................22
LABORATORY ACTIVITY NO.2 .................................................................................................................................25
WEEK 3: CLASSIFICATION OF SOFTWARE ............................................................................................................. 28
INTRODUCTION ....................................................................................................................................................28
CLASSIFICATION OF SOFTWARE ...............................................................................................................................28
LABORATORY ACTIVITY NO. 3 .................................................................................................................................30
WEEK 4: THE NUMBER SYSTEM............................................................................................................................ 33
INTRODUCTION ....................................................................................................................................................33
NUMBER SYSTEM .................................................................................................................................................33
NUMBER SYSTEM TABLE OF CONVERSION .................................................................................................................33
CONVERSION PROCEDURE......................................................................................................................................34
LABORATORY ACTIVITY NO. 4 .................................................................................................................................40
WEEK 5: INTRODUCTION TO PROGRAMMING ..................................................................................................... 43
INTRODUCTION ....................................................................................................................................................43
THE C COMPILER .................................................................................................................................................43
WEEK 6: PRINTING A LINE OF A TEXT ................................................................................................................... 47
INTRODUCTION ....................................................................................................................................................47
A SIMPLE C PROGRAM: PRINTING A LINE OF A TEXT ....................................................................................................47
LABORATORY ACTIVITY NO. 6 .................................................................................................................................49
WEEK 7: MEMORY CONCEPT ................................................................................................................................ 53
INTRODUCTION ....................................................................................................................................................53
MEMORY CONCEPT (UNDERSTANDING VARIABLES) .......................................................................................53
COMMON PROGRAMMING ERROR .................................................................................................................53
RULES OF OPERATOR PRECEDENCE .................................................................................................................53
LABORATORY ACTVITIY NO. 7 .................................................................................................................................54
WEEK 8: USING IF AND IF.. ELSE STATEMENT ...................................................................................................... 57
INTRODUCTION ....................................................................................................................................................57
DISCUSSION ........................................................................................................................................................57
LABORATORY ACTIVITY NO. 8 .................................................................................................................................59
WEEK 9: FORMULATING ALGORITHM .................................................................................................................. 62
INTRODUCTION ....................................................................................................................................................62
DISCUSSIONS.......................................................................................................................................................62
LABORATORY ACTVITY NO. 9..................................................................................................................................64
WEEK 10: THE GENERAL FORMAT OF THE FOR AND WHILE STATEMENT ............................................................. 70
INTRODUCTION ....................................................................................................................................................70
GENERAL FORMAT ...............................................................................................................................................70
EXAMPLES ..........................................................................................................................................................70
WEEK 11: UNDERSTANDING ALGORITHM ............................................................................................................ 72
INTRODUCTION ....................................................................................................................................................72
OBJECTIVES .........................................................................................................................................................72
USING FOR LOOP ..................................................................................................................................................72
LABORATORY ACTIVITY NO. 11 ...............................................................................................................................74
WEEK 12: FORMULATING ALGORITHM CASE STUDY ............................................................................................ 78
INTRODUCTION ....................................................................................................................................................78
ALGORITHM DIFFERENT CASES ...............................................................................................................................78
ASSIGNMENT OPERATORS ..............................................................................................................................78
PREINCREMENTING VS. POSTINCREMENTING ................................................................................................79
PSEUDOCODE ..................................................................................................................................................79
FLOW CHART ...................................................................................................................................................79
EXAMPLE (PROBLEM SOLVING) .......................................................................................................................80
WEEK 13: BREAK AND CONTINUE ........................................................................................................................ 81
INTRODUCTION ....................................................................................................................................................81
OBJECTIVES .........................................................................................................................................................81
BREAK AND CONTINUE STATEMENTS .............................................................................................................81
LABORATORY ACTIVITY NO. 13 ...............................................................................................................................83
WEEK 14: SWITCH MULTIPLE SELECTIONS ............................................................................................................ 85
INTRODUCTION ....................................................................................................................................................85
OBJECTIVES .........................................................................................................................................................85
DO WHILE REPETITION STATEMENT ................................................................................................................85
SWITCH MULTIPLE-SELECTION STATEMENT ...................................................................................................86
LABORATORY ACTIVITY NO. 14 ...............................................................................................................................88
WEEK 15: FUNCTIONS .......................................................................................................................................... 91
INTRODUCTION ....................................................................................................................................................91
C STANDARD LIBRARY ...........................................................................................................................................91
PROGRAMMER-DEFINED FUNCTIONS ........................................................................................................................91
MATH LIBRARY FUNCTIONS ....................................................................................................................................91
THE MATH LIBRARY FUNCTIONS .....................................................................................................................92
WEEK 16: MATH LIBRARY FUNCTIONS ................................................................................................................. 93
INTRODUCTION: ...................................................................................................................................................93
OBJECTIVES .........................................................................................................................................................93
EXAMPLE ............................................................................................................................................................93
LABORATORY ACTIVITY NO. 16 ...............................................................................................................................94
WEEK 17: RANDOM NUMBER GENERATIONS ...................................................................................................... 96
INTRODUCTION ....................................................................................................................................................96
OBJECTIVES .........................................................................................................................................................96
RAND FUNCTION ..................................................................................................................................................96
LABORATORY ACTIVITY NO. 17 ...............................................................................................................................98
WEEK 18: APPLICATION OF C IN SOLVING ENGINEERING FORMULAS ................................................................ 101
INTRODUCTION ..................................................................................................................................................101
OBJECTIVES .......................................................................................................................................................101
LABORATORY ACTIVITY NO. 18 .............................................................................................................................102
REFERENCES....................................................................................................................................................... 103
Course Details
Course Code : Comp224g/ CE214g/ …
Course Title : Computer Fundamentals and Programming
Units : 2 units lab
Commitment : 6 hrs per week
Course Description : This hands-on course provides a comprehensive introduction to computer
fundamentals and programming. In the beginning students learn the
fundamentals of computers. Afterwards, students will learn the computer
programming process. They’ll work on projects reflecting industry work
scenarios. Students also learn how to program using other important
programming languages and are introduced to various software tools that aid
in the many facets of the software development process.
Prerequisites : None
Textbook :
References : D. &. A. I. Paul Deitel, "C How to Program," in C How to Program, 10th Edition, 2017.
Couse Outcomes : After completion of the course the student should be able to:
1. Familiarize with the computer fundamentals
2. Use Compiler to write a C program
3. Analyze flow chart and create C program equivalent
4. Create a engineering program application
Resources Required : Workbook, PC with Good internet connections,
Software Required : Online C Compiler, C Free V5.0 or higher
Quizzes : None
Examination : Midterm and Final Examination in the form of exam and programming
Midterm Finals
Assessments Percentage Assessments Percentage
Major Exams 50% Major Exams 50%
Laboratory Exercises 40% Laboratory Exercises 40%
Attendance 10% Attendance 10%
Introduction
[1]A computer is a programmable device that stores, retrieves, and processes information. ... The
term was later given to a mechanical device as they began replacing the human computers.
Today's computers are electronic devices that accept data (input), process that data, produce output, and
store (storage) the results.
A computer is a apparatus that can be instructed to carry out sequences of arithmetic or logical
operations automatically via computer programming. Modern computers have the ability to follow
generalized sets of operations, called programs. These programs enable computers to perform an
extremely wide range of tasks. A "complete" computer including the hardware, the operating system
(main software), and peripheral equipment required and used for "full" operation can be referred to as a
computer system. This term may as well be used for a group of computers that are connected and work
together, in particular a computer network or computer group.
Computer overview
[1] Below is a picture of a computer with each of the main components. In the image below, you can see
the desktop computer, flat-panel display, speakers, keyboard, and mouse. We've also labeled each of the
input devices and output devices.
[1]The first digital computer and what most people think of as a computer was called the ENIAC. It was
built during World War II (1943-1946) and was designed to help automate the calculations being
completed by human computers. By doing these calculations on a computer, they could achieve results
much faster and with less errors.
Early computers like the ENIAC used vacuum tubes and were large (sometimes room size) and only found
in businesses, universities, or governments. Later, computers began utilizing transistors as well as smaller
and cheaper parts that allowed the ordinary person to own a computer.
In 1822, Charles Babbage conceptualized and began emerging the Difference Engine, considered
to be the first automatic computing machine. The Difference Engine was capable of computing several
sets of numbers and making hard copies of the results. Babbage received some help with
development of the Difference Engine from Ada Lovelace, considered by many to be the first
computer programmer for her work on the Difference Engine. Unfortunately, because of funding,
Babbage was never able to complete a full-scale functional version of this machine. In June 1991, the
London Science Museum completed the Difference Engine No 2 for the bicentennial year of Babbage's
birth and later completed the printing mechanism in 2000.
The ABC was an electrical computer that used more than 300 vacuum tubes for digital
computation, including binary math and Boolean logic, and had no CPU (was not
programmable). On October 19, 1973, US Federal Judge Earl R. Larson signed his decision that
the ENIAC patent by J. Presper Eckert and John Mauchly was invalid. In the decision, Larson named
Atanasoff the sole inventor.
The ENIAC was invented by J. Presper Eckert and John Mauchly at the University of
Pennsylvania and began construction in 1943 and was not completed until 1946. It occupied
about 1,800 square feet and used about 18,000 vacuum tubes, weighing almost 50 tons. Although
a judge later lined the ABC computer was the first digital computer, many still consider the ENIAC
to be the first digital computer because it was fully functional.
Intel introduces the first microprocessor, the Intel 4004, on November 15, 1971.
The Vietnamese-French engineer André Truong Trong Thi and Francois Gernelle developed
the Micral computer in 1973. Considered as the first microcomputer, it used the
Intel 8008 processor and was the first commercial non-assembly computer. It originally sold for
$1,750.
Commodore - In 1977, Commodore introduced its first computer, the "Commodore PET."
Compaq - In March 1983, Compaq released its first computer and the first 100% IBM-compatible
computer, the "Compaq Portable."
Dell - In 1985, Dell introduced its first computer, the "Turbo PC."
Hewlett Packard - In 1966, Hewlett Packard released its first general computer, the "HP-2115."
NEC - In 1958, NEC builds its first computer, the "NEAC 1101."
Toshiba - In 1954, Toshiba introduces its first computer, the "TAC" digital computer.
Definition of Terms
• Desktop computer is a personal computer in a form intended for regular use at a single
location desk/table due to its size and power requirements, as opposed to a laptop whose
rechargeable battery and compact dimensions allow it to be regularly carried and used in
different locations.
• Tablet Computer, commonly shortened to tablet, is a thin, flat mobile computer with a
touchscreen display, which in 2016 is usually color, processing circuitry, and a rechargeable
battery in a single device. Tablets often come equipped with sensors, including digital
cameras, a microphone, and an accelerometer.
• Smartphone is a mobile phone with an advanced mobile operating system which combines
features of a personal computer operating system with other features useful for mobile or
handheld use.
• Personal Digital Assistant (PDA), also known as a handheld PC, or personal data assistant,is a
mobile device that functions as a personal information manager. The term evolved from
Personal Desktop Assistant, a software term for an application that prompts or prods the user
of a computer with suggestions or provides quick reference to contacts and other lists.
• Compiler is a computer program (or a set of programs) that transforms source code written
in a programming language (the source language) into another computer language (the target
language), with the latter often having a binary form known as object code.
Introduction:
Computer – A collection of electronic parts that allow software programs to run that perform certain
tasks. A computer can accept input, change data, store data and display data. It contains a rich collection
of terminologies that facilitate its function smoothly.
Objectives:
Using the illustration on the next page encircle any 20 computer terminologies from the given word
puzzle.
10 Across
10 Down
F A N O V E N T I L A T I O N A A A G R A P H I C S D R A M
T M O N I T O R F G I O D E V I C E P Q W E R T Y I I O G A
S U I O L N O O M R O M I D E N S M U R R H H T U X R U I N
Y U I D J X A C P U B E Q S G E F E G F B E D E T A B T Y N
G S I E Q W E R T Y R T G P J D T G Y T G R D G S C R E E N
S Y S T E M U N I T E R E R R E H A L T T T Y H E R F R O M
J S U R A X B Y E K E Y B O A R D B A T B Z Y J A R X B T L
Q T W C O M P U T E R E D C O D E Y N C A M E R A A I E E E
Y E I A L L O G S S M A R E R S K T E D B E D E M M T T R D
T M N P I T P I U P I H I S J J E E R G T W I H O P T A A D
A A E S G M T N P E N V V S E A R S Z G E I Y D L A F G B S
B L R L H O I K B A I I E O E M O U S E S F E M E G O R Y T
L I S O T N C C E K S D R R E E U T A J V I Y I D E V E T O
E S S C H I S D E E U E S G T S T G T J C D R I V E E E E R
T A P K I T O R R R P O C O L E P R A P O I N T E R R B S A
Q N P R O O C O C E R C D H S E U F C C O N T R O L L E R G
D M D V D R O M D I U A I F G H T D D P X I D D N T O R G E
V F E G R G T H N H A R D D I S K E V U G E R R F C A E R S
D T R A T E R A F O R D R V R A R V D R F E T O R T D E E J
A Q R T U M O N O C H R O M E T Y R T G T E E M E R G R N M
B U X T M I C R O O M S I E P A T A C O N V E R T E R S S S
D I S K E T T E Y T E X Y V G A C O R D E Q E D C E Q A C T
C X E Q Z O H D M I T U V B X T U V W P O W E R S U P P L Y
COMPUTER TERMINOLOGY
10 Across
Terminology Description
Introduction
[2] Computer hardware is any physical device used in or with your machine, whereas
software is a group of programming code installed on your computer's hard drive. In other words,
hardware is something you can hold in your hand, whereas software cannot be held in your hand.
You can touch hardware, but you cannot touch software. Hardware is physical, and software
is virtual.the actual software.
For example, the computer monitor you are using to read this text, and the mouse you
are using to navigate this web page are computer hardware. The Internet browser allowing you
to view this page, and the operating system that the browser is running on are considered
software. A video card is hardware, and a computer game is software. You can touch and feel the
video card, and the computer uses it to play a computer game, but you cannot touch or feel the
programming code that makes up the computer game.
• Hardware refers to the physical elements of a computer. This is also sometime called the
machinery or the equipment of the computer. Examples of hardware in a computer are
the keyboard, the monitor, the mouse and the central processing unit. However, most of
a computer's hardware cannot be seen; in other words, it is not an external element of
the computer, but rather an internal one, surrounded by the computer's casing (tower).
A computer's hardware is comprised of many different parts, but perhaps the most
important of these is the motherboard. The motherboard is made up of even more parts
that power and control the computer.
HARDWARES
Are the parts of computer itself including the Central Processing Unit (CPU) and related
microchips and micro-circuitry, keyboards, monitors, case and drives
Clock Speed
• determines on how speed the processor perform specific function
• The first computer operates below 30 Megahertz
• The Pentium chips began at 75 MHz in the late 1990's
• Tends to double every year
•
2. Motherboard
• contains the circuitry and connections that allow the various component to
communicate with each other
• is actually even more central than the Central Processing Unit.
3. Hard Drive
• A Hard drive is a series of magnetic platters on an axle or spindle that stores tiny bits
of magnetic metal in patterns that it can read later
4. Keyboard
• Allows you to input data into your computer. It too can be wired or wireless, PS2 or
USB.
• The standard keyboard has 101 keys.
5. Removable Storage and/or Disk Drives
• disk -is the storage device which contains computer files - or software
• drive -is the mechanism that runs the disk.
6. Optical Drive
• Is a method for taking large amounts of information and storing it on shiny Disks,
like CDs and DVDs.
• Use lasers to read from this media, and in some cases, to write to it.
7. Mouse
The mouse can perform four actions:
• Point:
• Click:
• Double click
• Drag
8. Monitor
Commonly known as a "screen," the monitor gives you a visual display of what your
computer is up to.
a. CRT Monitor
CRT (Cathode Ray Tube) Monitors are built very similarly to older (tube)
television sets.
b. Flatscreen
LCD (Liquid Crystal Display)/ LED (Light Emitting Diode) Monitors are thin
and flat. They are light, compact, take up very little desk space.
9. PRINTER
The printer takes the information on your screen and transfers it to paper or a hard
copy
• Software, commonly known as programs or apps, consists of all the instructions that tell
the hardware how to perform a task. These instructions come from a software developer
in the form that will be accepted by the platform (operating system + CPU) that they are
based on. For example, a program that is designed for the Windows operating system will
only work for that specific operating system. Compatibility of software will vary as the
design of the software and the operating system differ. Software that is designed for
Windows XP may experience a compatibility issue when running under Windows 2000 or
NT.
SOFTWARES
1. Systems software
Includes the operating system and all the utilities that enable the computer to
function.
2. Applications software
Includes programs that do real work for users. For example, word processors,
spreadsheets, and database management systems fall under the category of
applications software.
3. Programming software
SYSTEM SOFTWARE
1. Operating System
Is an interface between hardware and user which is responsible for the
management and coordination of activities and the sharing of the resources of
the computer that acts as a host for computing applications run on the machine.
2. Utility
Is computer software designed to help manage and tune the computer
hardware, operating system or application software by performing a single task
or a small range of tasks
APPLICATION SOFTWARE
Application software allows end users to accomplish one or more specific (not directly
computer development related) tasks.
▪ Application software
▪ Industrial Automation
▪ Business Software
▪ Computer Games
▪ Databases
▪ Image Editing
▪ Spreadsheet
▪ Word Processing
PROGRAMMING SOFTWARE
COMPUTER LANGUAGES
A. Machine Languages
• Is the “natural language” of a particular computer
• It is defined by the hardware design of that computer
• Generally consist of strings of numbers (ultimately reduced to 1’s and 0’s)
that instruct computers to perform their most elementary operation at a
time
B. Assembly Languages
• English-like abbreviations to represent elementary operations
• English-like abbreviations to represent elementary operations
C. High-Level Languages
▪ Single statements could be written to accomplish substantial tasks.
FORTRAN
• FORmula TRANslator
• Was developed by IBM Corporation in the 1950s to be used for scientific and
engineering applications that require complex mathematical computations
COBOL
• Still widely used especially in engineering applications
• Common Business Oriented Language
• Was developed in 1959 by computer manufacturers, the government and industrial
computer users
• Used for commercial applications that require precise and efficient manipulation of
large amount of data
ADA
• A programming language was developed under the sponsorship of the U.S. Department
of Defense (DOD) during 1970s and early 1980s
• Named after Lady Ada Lovelace
OPERATING SYSTEM
Is an interface between hardware and user which is responsible for the management and
coordination of activities and the sharing of the resources of the computer.
▪ 1960
▪ the advancement of the commercial computer services started the DOS (DISK
OPERATING SYSTEM)
MULTIPROGRAMMING
Involves the simultaneous operation of many jobs on the computer
PERSONAL COMPUTING
DISTRIBUTED COMPUTING
Computers are linked together in computer networks, sometimes over telephone lines
(LAN)
1. File Servers –Offer a common store data that may be used by Client
HISTORY OF C
Evolved from two previous languages
1. BCPL
2. B
BCPL
(Basic Combined Programming Language)
• Is a computer programming language designed by Martin Richards of the University of
Cambridge in 1967 as a language for writing operation systems Software and compilers.
B language
• Modeled by Ken Thompson after their counterparts in BCPL and used this language in 1970
to create versions of the UNIX operating system at Bell Laboratories on a DEC PDP-7
computer
C language
• Uses many of the important concepts of BCPL and B while adding data typing and other
powerful features
• Initially became widely known as the development language of the UNIX operating system
C Standard Library
• C programs consist of modules or pieces called functions
• You can program all the functions you need to form a C program
C++
• Is a superset of C
• Developed by Bjarne Stroustrup at Bell Laboratories
• Provides a number of features that “spruce up” the C language
• Capable for object-oriented programming
Java
• The name was originated from a coffee place name Java
• Develop by the Sun Microsystems
• It is an internal corporate research project code-named Green in 1991
• The name was originated from a coffee place name Java
• Develop by the Sun Microsystems
• It is an internal corporate research project code-named Green in 1991
BASIC
Beginner’s All-Purpose Symbolic Instruction Code
• was developed in the mid 1960s by professors John Kemeny and Thomas Kurtz of
Dartmount College as a language for writing simple programs
• BASIC’s primary purpose was to familiarize novices with programming techniques
Visual Basic
• Visual Basic was introduced by Microsoft in 1991 to simplify the process of developing
Microsoft Windows applications.
Hardware Trends
• The programming community thrives on a continuing stream of dramatic improvements in
hardware, software and communication technologies
Hardware Trends
• Every year or two, computer performance tends to double while computer prices continue
drop
• Hardware Trends
• Computer System Architecture
• Processors
• Secondary Storage Devices
• Removable Storage Devices
• RAM (Random Access Memory)
• Optical Drives
• Monitors
Internet
• Several research programs started to explore and articulate principles of communications
between physically separate systems, leading to the development of the packet switching
model of digital networking
• It is a network of networks that consists of millions of private, public, academic, business,
and government networks, of local to global scope, that are linked by a broad array of
electronic and optical networking technologies
• Internet is a global system of interconnected computer networks that use the standard
Internet Protocol Suite (TCP/IP) to serve billions of users worldwide
• Internet is a short form of the technical term “internetwork", the result of interconnecting
computer networks with special gateways (routers)
• It is a hardware and software infrastructure that provides connectivity between computers
Cloud
• Also referred to as a network cloud
In telecommunications, a cloud refers to a public or semi-public space on transmission lines
that exists between the end points of a transmission
Introduction:
A computer system consists of two major elements: hardware and software. Computer hardware is the
collection of all the parts you can physically touch. Computer software, on the other hand, is not
something you can touch. Software is a set of instructions for a computer to perform specific operations.
Objectives:
Procedure(s):
CLASSIFICATION
Web Browser
Search Engine
Microprocessor
Mouse
Word Processor
Spreadsheet
Cords
Screen
Apps
Operating System
PREFIXES MEASUREMENTS
1 000 000 Hertz
1 000 Hertz
2.05 GHz
1.1 GHz
3 150 000 Hertz
1 x 10-3 sec
1 psec
1 usec
1 x 10-9 sec
1 x 10-15 sec
V. List down 4 hardware and 5 software acronyms and give its description.
Acronym Description
HDD Hard Disk Drive
VII. What is the advantage of using a dot-matrix printer compare to ink jet printer?
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
Introduction
[3]Software was simple in nature and hence, software development was a simple activity during early
time. However, as technology improved, software became more multifaceted and software projects grew
larger. Software development now necessitated the presence of a team, which could prepare detailed
plans and designs, carry out testing, develop instinctive user interfaces, and integrate all these activities
into a system. This new approach led to the appearance of a discipline known as software engineering.
Classification of Software
[3]Software can be applied in countless fields such as business, education, social sector, and other
fields. It is designed to suit some specific goals such as data processing, information sharing,
communication, and so on. It is classified according to the range of potential of applications. These
classifications are listed below.
System software: This class of software manages and controls the core operations of a
computer system. It is a group of programs, which is responsible for using computer resources
efficiently and effectively. For example, an operating system is a system software, which controls
the hardware, manages memory and multitasking functions, and acts as an interface between
application programs and the computer.
Real-time software: This class of software detects, analyzes, and controls real world events as they
occur. Generally, a real-time system guarantees a response to an external event within a specified period
of time. An example of real-time software is the software used for weather forecasting that collects and
processes parameters like temperature and humidity from the external environment to forecast the
weather. Most of the defense organizations all over the world use real-time software to control their
military hardware.
Business software: This class of software is widely used in areas where management and control of
financial actions is of greatest importance. The fundamental component of a business system comprises
payroll, inventory, and accounting software that permit the user to access relevant data from
the database. These activities are usually performed with the help of specialized business software that
facilitates efficient framework in business operations and in management decisions.
Engineering and scientific software: This class of software has emerged as a powerful tool in the
research and development of next generation technology. Applications such as the study of celestial
bodies, under-surface activities, and programming of an orbital path for space shuttles are heavily
dependent on engineering and scientific software. This software is designed to perform precise
calculations on complex numerical data that are obtained during real time environment.
Artificial intelligence (AI) software: This class of software is used where the problem-solving system
is non-algorithmic in nature. The solutions of such problems are generally non-agreeable to computation
or straightforward analysis. Instead, these problems require specific problem-solving strategies that
include expert system, pattern recognition, and game-playing techniques. In addition, they involve
different kinds of search techniques which include the use of heuristics. The role of artificial intelligence
software is to add certain degrees of intelligence to the mechanical hardware in order to get the desired
work done in an agile manner.
Web-based software: This class of software acts as an interface between the user and the Internet. Data
on the Internet is in the form of script, audio, or video format, linked with hyperlinks. Web browser is a
software that retrieves web pages from the Internet. The software incorporates executable instructions
written in special scripting languages such as CGI or ASP. Apart from providing navigation on the Web, this
software also supports additional features that are useful while surfing the Internet.
Personal computer (PC) software: This class of software is used for both official and personal use.
The personal computer software market has grown over in the last two decades from normal text editor
to word processor and from simple paintbrush to advanced image-editing software. This software is used
mainly in almost every field, whether it is database management system, financial accounting package, or
multimedia-based software. It has emerged as a versatile tool for routine applications.
Introduction:
Operating Systems are a collection of programs that make the computer hardware conveniently available
to the user and also hide the complexities of the computer's operation. Computer software, or simply
software, is a generic term that refers to a collection of data or computer instructions that tell the
computer how to work, in contrast to the physical hardware from which the system is built, that actually
performs the work.
Objectives:
Procedure(s):
I. How does internet browser affect the browse time? Defend your answer.
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
II. What is the difference between internet and world wide web
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
III. Differentiate the 3 computer languages and which of those is the most programmer friendly
language?
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
Acronyms Descriptions
P2P
HTTP
COPPA
URL
HTML
BW
BITNET
ARPANET
IEN
SSE
a. Multiprogramming
b. Client to Server Computing
c. Distributed Computing
d. Timesharing Operation
a. Multiprogramming
c. Distributed Computing
d. Timesharing Operation
Introduction
[4]A number system is defined as a system of writing for expressing numbers. It is the mathematical
notation for representing numbers of a given set by using digits or other symbols in a consistent manner.
It provides a unique representation of every number and represents the arithmetic and algebraic structure
of the figures. It also allows us to operate arithmetic operations like addition, subtraction, and division.
Number System
There are various types of the number system in mathematics. The four most common number
system types are:
0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Conversion Procedure
Hexadecimal to Binary
3CF16=_______________2
3 C F
3CF16 = 001111001111 2
9AF16=_______________2
9 A F
9AF16 = 100110101111 2
Hexadecimal to Decimal
3C16 = ____________10
3C16 = 6010
3BE16 = ____________10
3BE16 = 95810
Decimal to Hexadecimal
247910 = _________16
9< 16
247910 = 9AF16
643410 = _________16
25 ÷ 16 = 1.5625 (0.5625 x 16 = 9)
1 < 16
643410 = 192216
Binary to Decimal
11012 = _________10
1 x 20 = 1
0 x 21 = 0
1 x 22 = 4
1 x 23 = 8
13
11012 = 1310
1112 = _________10
1 x 20 = 1
1 x 21 = 2
1 x 22 = 4
1112 = 710
Decimal to Binary
2410 = __________2
24 ÷ 2 =12 r.=0
12 ÷ 2 = 6 r.=0
6 ÷ 2 =3 r.=0
3÷2=1 r. = 1
2410 = 110002
Binary to Hexadecimal
0011010101001112 = __________16
[001][1010][1010][0111] = 1AA7
0011010101001112 = 1AA716
111101101112 = __________16
[111][1011][0111] = 7B7
111101101112 = 7B716
Octal to Decimal
758=_______________10
5 x 80 = 5
7 x 81 = 56
5 + 56 = 61
758= 6110
75628 = ____________10
2 x 80 = 2
6 x 81 = 48
5 x 82 = 320
7 x 83 = 3584
3954
75628 = 3954 10
Decimal to Octal
20010 = _____________8
200 ÷ 8 = 25 (.0 x 8 = 0 )
25 ÷ 8 = 3 (.125 x 8 = 1)
3<8
20010 = 3108
102310 = _____________8
127 ÷ 8 = 15 (.875 x 8 = 7)
15 ÷ 8 = 1 (.875 x 8 = 7)
1<8
102310 = 17778
Octal to Binary
758 = ___________2
7 5
111 101
758 = 1111012
75678 = ___________2
7 5 6 7
75678 = 1111011101112
Binary to Octal
1111011101112 = ____________8
7 5 6 7
1111011101112 = 75678
101010101112 = ____________8
2 5 2 7
11010101112 = 25278
6738 = ___________16
6 7 3
1 1011 1011
1 B B
6738 = 1BB16
AAA16 = ___________8
A A A
5 2 5 2
AAA16 = 52528
Objectives:
Procedure(s):
717
101011010
416
111101111
435
CAFE
213
1001010101
318
COMPUTATIONS:
1.
2.
3.
4.
5.
COMPUTATIONS:
6.
7.
8.
9.
10.
Introduction
[5]You may already have used software, maybe for word processing or spreadsheets, to solve
problems. Perhaps now you are curious to learn how programmers write software. A program is a set of
step-by-step instructions that directs the computer to do the tasks you want it to do and produce the
output you want.
• Programming helps you know computers. The computer is only a tool. If you learn how to write
simple programs, you will gain more knowledge about how a computer works.
• Writing a few simple programs increases your confidence level. Many people find great personal
satisfaction in creating a set of instructions that solve a problem.
• Learning programming lets you find out quickly whether you like programming and whether you
have the analytical turn of mind programmers need. Even if you decide that programming is not
for you, understanding the process certainly will increase your appreciation of what
programmers and computers can do.
A set of instructions that provides a way of telling a computer what operations to perform is called a
programming language. There is not, however, just one programming language; there are many. In this
chapter you will learn about controlling a computer through the process of programming. You may even
discover that you might want to become a programmer.
The C Compiler
[6]A compiler is a special program that processes statements written in a particular programming
language and turns them into machine language that a computer's processor uses. Typically, a
programmer writes language scripts in a language such as Pascal or C one line at a time using an editor
Offline Compiler
Offline compiler used to be a standalone compiler but not limited to a library package that
enable to run a various computer script, usually need license and some are open source
a. C Free
i. High level language programming software
ii. Window Base Compiler
Following parts:
1. Main menu and Toolbar
2. Tab bar
3. Code editor
4. Symbol window and Symbol panel
5. Message window
6. File Tree window
7. Status bar
CODE EDITOR
SYMBOL WINDOW AND
SYMBOL PANEL
MESSAGE BAR
STATUS BAR
b. Tab Bar
o Tab bar creates tabs for all opened files, and helps you switch among opened files
quickly
c. Code Editor
e. Message Bar
o Shows the messages after compilation
Online Compiler
Online compiler is a compiler that usually saved at the cloud and can be access only if you are
connected to the network, usually it is free to use and open source.
Introduction
[7] The C language facilitates a structured and disciplined approach to computer-program design. In this
chapter we introduce C programming and present several examples that illustrate many important
features of C.
Example 1.1
\\ Backslash. Insert a
backslash character in a
string
\" Double quote. Insert a
double quote character in a
string
Example 1.2
1. /* Example 2 */
2.
3. #include <stdio.h>
4.
5. /* function main begins program execution */
6.
7. int main()
8. {
9. printf( “Computer\nProgramming!\n” );
10.
11. return 0; /* program ended successfully */
12.
13. } /* end function main */
Introduction:
C is a powerful general-purpose programming language. It is fast, portable and available in all platforms.
If you are new to programming, C is a good choice to start your programming journey. C is a general-
purpose programming language used for wide range of applications from Operating systems like Windows
and iOS to software that is used for creating 3D movies. C programming is highly efficient. That’s the main
reason why it’s very popular despite being more than 40 years old.
Standard C programs are portable. The source code written in one system works in another operating
system without any change.
Objectives:
Procedure(s):
A.
B.
\n\n
\a\a\a
\"\\\\\"
\"\"
\t\t\t
III. Using the techniques you learned, write a program that display these message
C Programming is easy?
BINARY OCT
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
Questions:
#include <stdio.h>
______________________________________________
______________________________________________
______________________________________________
int main()
______________________________________________
______________________________________________
______________________________________________
printf
______________________________________________
______________________________________________
______________________________________________
return 0
______________________________________________
______________________________________________
______________________________________________
CONCLUSION: (30pts.)
Introduction
[8] A memory is just like a human brain. It is used to store data and instructions. Computer memory
is the storage space in the computer, where data is to be processed and instructions required for
processing are kept. The memory is divided into large number of small parts called cells. Each location or
cell has a unique address, which varies from zero to memory size minus one.
Destructive Read-in
▪ The process of reading information into a memory wherein the value replaces the
previous value in that location
▪ An attempt to divide by zero is normally undefined on computer systems and generally results in
a fatal error
▪ Fatal error are errors that causes the program to terminate immediately without having
successfully performed its job
▪ Non-fatal errors allow programs to run to completion, often producing incorrect results
Arithmetic Operations in C
Introduction:
Arithmetic Operators in C. The Arithmetic operators are some of the C Programming Operator, which
are used to perform arithmetic operations includes operators like Addition, Subtraction, Multiplication,
Division and Modulus. All these operators are binary operators which means they operate on two
operands
Objectives:
Procedure(s):
A. (Digits of an Integer) 40 pts. Write a program that inputs a five-digit integer, separates the
integer into its digits and prints them separated by three spaces each. [Hint: Use the integer
division and modulus operators.] For example, if the user types in 11101, the program should
print:
1 1 1 0 1
B. (Diameter, Circumference and Area of a Circle)30pts. Write a program that reads in the radius
of a circle as an integer and prints the circle’s diameter, circumference and area. Use the
constant value 3.14159 for π. Do all calculations in output statements.
C. (Distance, Rate, Time Problem) 30pts. Write a program that reads in the rate and time of the
given body and compute for the distance travelled.
Answer Sheet:
A.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
B.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
C.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
Introduction
[7] If the Boolean expression evaluates to true, then the if block will be executed, otherwise, the
else block will be executed. C programming language assumes any non-zero and non-null values as true,
and if it is either zero or null, then it is assumed as false value.
Discussion
Example
1. /* Fig.2.13: fig02.13.c
2. Using if statements, relational
3. operators, and equality operators */
4.
5. #include <stdio.h>
6.
7. /*function main begins program execution */
8. int main()
9. {
10. int num1; /*first number to be read from user */
11. int num2; /*second number to be read from user */
12.
13. printf("Enter two integers and I will tell you\n");
14. printf("the relationships they satisfy:\n");
15.
16. scanf("%d%d", &num1, &num2); /*read two integers*/
17.
18. if (num1==num2){
19. printf("%d is equal to %d\n",num1,num2);
20. } /*endif*/
21.
22. if (num1!=num2){
23. printf("%d is not equal to %d\n",num1,num2);
24. } /*endif*/
25.
26. if (num1>num2){
27. printf("%d is greater than %d\n",num1,num2);
28. } /*endif*/
29.
30. if (num1<num2){
31. printf("%d is less than to %d\n",num1,num2);
32. } /*endif*/
33.
34. return 0;/*indicate that program ended successfully*/
35. } /*end function main*/
Example
1. /* Example 3.2
2. A Grade Program */
3.
4. #include <stdio.h>
5.
6. int main()
7. {
8. int grade;
9.
10. printf("\nThis program will tell you if you passed or failed");
11. printf("the subject\n\n");
12. printf(" \nEnter your grade between (0 to 100): ");
13. scanf("%d",&grade);
14.
15. if (grade>100)
16. printf("\n\nNOT A VALID GRADE!!! \n\n\n");
17. else if (grade==100)
18. printf("\n\nP E R F E C T !!!: Your grade is A\n\n");
19. else if (grade>=89)
20. printf("\n\nPassed: Your grade is A\n\n");
21. else if (grade>=79)
22. printf("\n\nPassed: Your grade is B\n\n");
23. else if (grade>=69)
24. printf("\n\nPassed: Your grade is C\n\n");
25. else if (grade>=59)
26. printf("\n\nPassed: Your grade is D\n\n");
27. else
28. printf("\n\nFAILED ! ! ! \n\n\n");
29.
30. return 0;
31. }
Objectives:
Procedure(s):
A. (Arithmetic, Smallest and Largest) 40 pts. Write a program that inputs three integers from the
keyboard and prints the sum, average, product, smallest and largest of these numbers. The screen
dialog should appear as follows:
B. (Odd or Even)30 pts. Write a program that reads an integer and determines and prints whether
it’s odd or even. [Hint: Use the modulus operator. An even number is a multiple of two. Any
multiple of two leaves a remainder of zero when divided by 2.]
C. (Multiples)30 pts. Write a program that reads in two integers and determines and prints if the
first is a multiple of the second. [Hint: Use the modulus operator.]
Answer Sheet:
A.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
B.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
C.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
Introduction
[9]To make a computer do anything, you have to write a computer program. To write a computer
program, you have to tell the computer, step by step, exactly what you want it to do. The computer then
"executes" the program, following each step mechanically, to accomplish the end goal.
When you are telling the computer what to do, you also get to choose how it's going to do it. That's
where computer algorithms come in. The algorithm is the basic technique used to get the job done.
Discussions
FORMULATING ALGORITHM
Algorithms
Control Structures
1. Sequential execution
• Statements in a program are executed one after the other in the order
in which they are written
2. Transfer of control
Pseudocode
Examples
Example 1:
Pseudocode
1. If student’s grade is greater than or equal to 60
2. Print “Passed”
Equivalent C program
1. if (grade >= 60)
2. printf (“Passed\n”);
Example 2:
Pseudocode
1. If student’s grade is greater than or equal to 60
2. Print “Passed”
3. Else
4. Print “Failed”
Equivalent C Program
1. if (grade >= 60)
2. printf (“Passed\n”);
3. else
4. printf(“Failed\n”);
Objectives:
Procedure(s):
I. Compile the following source code and write the output in the box
A.
1. /* A counter from 1 to 10
2. using while repetition statement */
3.
4. #include <stdio.h>
5.
6. int main()
7. {
8. int counter=1;
9.
10. while(counter<=10)
11. {
12. printf("%d\n",counter);
13. counter=counter+1;
14. }
15.
16. return 0;
17. }
B.
1. /* A countdown from 10 to 1
2. using while repetition statement */
3.
4. #include <stdio.h>
5.
6. int main()
7. {
8. int counter=10;
9. while(counter>=1)
10. {
11. printf("%d\n",counter);
12. counter=counter-1;
13. }
14. return 0;
15. }
OPERATORS DESCRIPTION
==
>
<
>=
<=
1. /* A countdown from 1 to 10
2. using for repetition statement */
3.
4. #include <stdio.h>
5.
6. int main()
7. {
8. int counter;
9.
10. for(counter=1;counter<=10;counter++)
11. {
12. printf("%d\t",counter);
13. }
14. printf("\n");
15.
16. return 0;
17. }
B.
1. /* A countdown from 10 to 1
2. using for repetition statement */
3.
4. #include <stdio.h>
5.
6. int main()
7. {
8. int counter;
9.
10. for(counter=10;counter>=1;counter--)
11. {
12. printf("%d\t",counter);
13. }
14. printf("\n");
15.
16. return 0;
17. }
Questions:
while
______________________________________________
______________________________________________
______________________________________________
for
______________________________________________
______________________________________________
______________________________________________
counter++
______________________________________________
______________________________________________
______________________________________________
counter--
______________________________________________
______________________________________________
______________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
_______________
1
4
9
16
25
36
49
64
81
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
Week 10: The General Format Of The For And While Statement
Introduction
While loop executes until the condition turns to false, that is first the condition is checked and if it is true
then body is executed and same continues, but where as in for loop first the variable is intialized if it is
declared and the codition is evaluated and then body of loop finally increment/decrement of variable
happens and same continues.
General Format
while (expression2){
statement;
expression3;
Examples
These two example having the same output but the first one use while loop and the second using for
loop, notice the differences
WHILE LOOP)
1. #include <stdio.h>
2.
3. int main()
4. {
5. int counter=1; /* initialize the counter to 1 */
6.
7. while(counter<=10)
8. {
9. printf("%d\n",counter);
10. counter++; /* increment the counter by 1 */
11. }
12.
13. return 0;
14. }
(FOR LOOP)
1. #include <stdio.h>
2.
3. int main()
4. {
5. int counter; /* initialize the variable counter*/
6.
7. for(counter=1;counter<=10;counter++)
8. {
9. printf("%d\n",counter);
10. }
11.
12. return 0;
13. }
Introduction
Objectives
int main() {
int i;
Output
1 2 3 4 5 6 7 8 9 10
i is initialized to 1.
The test expression i < 11 is evaluated. Since 1 less than 11 is true, the body
of for loop is executed. This will print the 1 (value of i ) on the screen.
The update statement ++i is executed. Now, the value of i will be 2. Again, the test
expression is evaluated to true, and the body of for loop is executed. This will
print 2 (value of i ) on the screen.
Again, the update statement ++i is executed and the test expression i < 11 is
evaluated. This process goes on until i becomes 11.
When i becomes 11, i < 11 will be false, and the for loop terminates.
Procedure(s):
I. Compile the following source code and write the output on the box
II. Provide a simple explanation for the output
A.
B.
1. /* using for loop to
2. Convert kilometer to mile */
3.
4. #include <stdio.h>
5.
6. main()
7. {
8. float km;
9.
10. printf("Kilometer Mile\n");
11.
12. for(km=0;km<=40;km+=10)
13. printf("%10.2f%10.2f\n",km,0.621371*km);
14.
15. return 0;
16. }
OPERATORS DESCRIPTION
%10.2f
%15.2f
c+=10
km+=10
km<=40
A.
Base on the Item III.A follow the instructions and write the output on the box
OUTPUT
Questions:
______________________________________________
______________________________________________
______________________________________________
if (total_gallons!=0)
______________________________________________
______________________________________________
______________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
_______________.
6. Write a code using while loop that will compute for the
salary of a given person, given the rate/hour and the
number of hours.
SAMPLE OUTPUT:
Introduction
[10] A control structure is like a block of programming that analyses variables and chooses a
direction in which to go based on given parameters. The term flow control details the direction the
program takes (which way program control "flows"). Hence it is the basic decision-making process
in computing; It is a prediction.
ASSIGNMENT OPERATORS
c=c+3;
c +=3;
The += operator adds the value of the expression on the right of the operator to the value of
variable on the left of the operator and stores the result in the variable on the left of the
operator
variable operator=expression;
Example
1. #include <stdio.h>
2.
3. int main()
4. {
5. int c;
6.
7. c=5;
8. printf("%d\n",c);
9. printf("%d\n",c++);
10. printf("%d\n\n",c);
11.
12. c=5;
13. printf("%d\n",c);
14. printf("%d\n",++c);
15. printf("%d\n",c);
16.
17. return 0;
18. }
PSEUDOCODE
FLOW CHART
• Is a graphical representation of an algorithm
• Are drawn using certain special symbols such as ovals, rectangle, diamonds, and small circles
connected by arrows –flowlines
• Create an Algorithm
• Create a Pseudocode
• Convert Pseudocode into a C Equivalent Program
B. C Program
1. #include <stdio.h>
2.
3. int main()
4. {
5. float sales=0;
6. float salary=0;
7.
8. printf("Enter sales in dollars (-1 to end):");
9. scanf("%f",&sales);
10.
11. while(sales!=-1){
12.
13. salary=0.09*sales+200;
14. printf("Salary is: %.2f\n",salary;
15. printf("Enter sales in dollars (-1 to
end):");
16. scanf("%f",&sales;
17. }
18.
19. }
Introduction
The break statement allows you to exit a loop from any point within its body, bypassing its normal
termination expression. When the break statement is encountered inside a loop, the loop is immediately
terminated, and program control resumes at the next statement following the loop. The break statement
can be used with all three of C's loops. You can have as many statements within a loop as you desire. It is
generally best to use the break for special purposes, not as your normal loop exit. break is also used in
conjunction with functions and case statements.
Objectives
Example
B. Continue Statement
Example
OUTPUT:
B.
1. #include <stdio.h>
2. int main()
3. {
4. int x;
5.
6. for (x=0;x<=200;x+=5){
7.
8. if (x==45){
9. continue;
10. }
11. printf("%d\t",x);
12. }
13.
14. return 0;
15.
16. }
OUTPUT:
Introduction
The switch multiple selection statement can be used to perform many different actions based only on a
single integer value. Note however, the switch statement can only be applied in narrow circumstances.
The tests must be constants and be integers.
Objectives
do
statement
while (condition);
do {
statement
}while (condition);
Example
Example
1. #include <stdio.h>
2.
3. int main()
4. {
5. int grade;
6. int aCount=0;
7. int bCount=0;
8. int cCount=0;
9. int dCount=0;
10. int fCount=0;
11.
12.
13. printf( "Enter the letter grades. \n" );
14. printf( "Enter the EOF charcter to end input. \n" );
15.
16. while ((grade=getchar())!=EOF){
17. switch (grade){
18. case 'A':
19. case 'a':
20. ++aCount;
21. break;
22.
23. case 'B':
24. case 'b':
25. ++bCount;
26. break;
27.
28. case 'C':
29. case 'c':
30. ++cCount;
31. break;
32.
33. case 'D':
34. case 'd':
35. ++dCount;
36. break;
37.
38. case 'F':
39. case 'f':
40. ++fCount;
41. break;
42.
43. case '\n':
Description:
The program will ask any letters from A to D and it will print a message according to the
letter entered. If (A) is pressed it will print (100). If (B, C and D) it will print (90,80 and 70)
respectively. If other letters it will print Non-Catergorized.
A Print 100
B Print 90
C Print 80
D Print 70
Other Letters Non-Categorized
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
II. Write a program using do...while to display the following sequence of number using 1 variable
only
2 20 200
4 40 400
6 60 600
8 80 800
10 100 1000
12 120 1200
14 140 1400
16 160 1600
18 180 1800
20 200 2000
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
III. What is the difference between using while repetition compare to do...while repetition?
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________.
IV. What are the disadavantages of using switch case multiple selection compare to the other loop
codes?
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________.
Conclusion: (30pts.)
Introduction
In c, we can divide a large program into the basic building blocks known as function.
The function contains the set of programming statements enclosed by {}. A function can be called multiple
times to provide reusability and modularity to the C program.
C mathematical operations are a group of functions in the standard library of the C programming
language implementing basic mathematical functions. The math.h header defines various mathematical
functions and one macro. All the functions available in this library take double as an argument and return
double as the result.
C Standard Library
▪ Provides a rich collection of functions for performing common mathematical calculations, string
manipulation, character manipulation, input/output, and many other useful operations
▪ The functions printf, scanf and pow are standard library functions
Programmer-defined functions
▪ The programmer can write functions to define specific task that may be used at many points in a
program
printf("%.2f",sqrt(900.0));
▪ Include the math header by using the preprocessor directive #include <math.h> when using
functions in the math library
Introduction:
C mathematical operations are a group of functions in the standard library of the C programming language
implementing basic mathematical functions. The math.h header defines various mathematical functions
and one macro. All the functions available in this library take double as an argument and return double as
the result.
Objectives
Example
Answer Sheet:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
Introduction
The C library function int rand(void) returns a pseudo-random number in the range of 0 to RAND_MAX.
RAND_MAX is a constant whose default value may vary between implementations but it is granted to be
at least 32767.
Objectives
1. To be able to use the math standard library to solve for some mathematical calculation
2. To be able to use the standard library to generate a pseudorandom numbers and a srand
function
3. To use the math and random function for some application
Rand function
The rand function generates an integer between 0 and RAND_MAX (a symbolic constant defined in the
<stdlib.h> header.
If rand truly produces integers at random, every number between 0 and RAND_MAX has an equal
chance of being chosen each time rand is called.
Example
1. /*Shifted, scaled integers produced by 1 + rand() % 6 */
2.
3. #include <stdio.h>
4. #include <stdlib.h>
5.
6. /* Function main begins program execution */
7.
8. int main()
9. {
10. int i;
11.
12. for (i=1;i<=20;i++)
13. {
14. printf("%10d",1+(rand()%6));
15.
16. if(i%5==0)
17. {
18. printf("\n");
19. }
20. }
21.
22. return 0;
23. }
A.
4.01
5.25
2.12
1.40
0.60
A.
1. #include <stdio.h>
2. #include <stdlib.h>
3.
4. int main(){
5. int i;
6.
7. for(i=1;i<=30;i++){
8. printf("%d\t",5+(rand()%20));
9.
10. if (i%5==0)
11. printf("\n");
12. }
13. return 0;
14. }
Output:
0-32767
1-4
6-10
49-100
57-77
999-1110
2110-2111
76-80
1001-1500
2,4,6,8,10
II. Programming:
Introduction
Engineering Approach contains almost unlimited formulas that solve different scientific problems.
And it takes a lot of calculation in proving laws and theorems. Using a software based application aids
engineers and researchers to validate and speed up data gathering and processes, one of the powerful
computer language that they used is the C language.
Objectives
Write any Engineering Formula Calculator that use all the following commands
a. If and If… Else
b. While or For Loops
c. A Sentinel Controlled Loop
d. A Math Functions not less than 5 functions
References
[3] "https://ecomputernotes.com/software-engineering/characteristics-and-classification-of-
software," [Online].
[7] D. &. A. I. Paul Deitel, "C How to Program," in C How to Program, 10th Edition, 2017.