Computer Programming (2)
Computer Programming (2)
COMPUTER PROGRAMMING
COMPUTER SYSTEMS
―A Computer is an electronic device that stores, manipulates and retrieves the data.‖ We
can also refer computer computes the information supplied to it and generates data. A System is a
group of several objects with a process. For Example: Educational System involves teacher,
students (objects). Teacher teaches subject to students i.e., teaching (process).
Similarly a computer system can have objects andprocess.
The following are the objects of computer System
a) User ( A person who uses thecomputer)
b) Hardware
c) Software
Hardware: Hardware of a computer system can be referred as anything which we can touchand feel.
Example : Keyboard andMouse.
The hardware of a computer system can be classified as
Input Devices(I/P)
Processing Devices (CPU)
Output Devices(O/P)
CPU
INPUT OUTPU
T
COMPUTER SOFTWARE
Software of a computer system can be referred as anything which we can feel andsee.
Example: Windows,icons
Computer software is divided in to two broad categories: system software and application
software .System software manages the computer resources .It provides the interface between the
hardware and the users. Application software, on the other hand is directly responsible for helping
users solve their problems.
System Software
System software consists of programs that manage the hardware resources of a computer and
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
perform required information processing tasks. These programs are divided into three classes: the
operating system, system support, and systemdevelopment.
The operating system provides services such as a user interface, file and database access, and
interfaces to communication systems such as Internet protocols. The primary purpose of this
software is to keep the system operating in an efficient manner while allowing the users access to
the system.
System support software provides system utilities and other operating services. Examples of
system utilities are sort programs and disk format programs. Operating services consists of
programs that provide performance statistics for the operational staff and security monitors to
protect the system and data.
The last system software category, system development software, includes the language translators
that convert programs into machine language for execution ,debugging tools to ensure that the programs
are error free and computer –assisted software engineering(CASE) systems.
Application software
Application software is broken in to two classes: general-purpose software and application –
specific software. General purpose software is purchased from a software developer and can be
used for more than one application. Examples of general purpose software include word processors,
database management systems ,and computer aided design systems. They are labeled general
purpose because they can solve a variety of user computing problems.
Application –specific software can be used only for its intended purpose.
A general ledger system used by accountants and a material requirements planning system used by a
manufacturing organization are examples of application-specific software. They can be used only
for the task for which they were designed they cannot be used for other generalized tasks. The
relationship between system and application software is shown below. In this figure, each circle
represents an interface point .The inner core is hard ware. The user is represented by the out layer.
To work with the system, the typical user uses some form of application software. The application
software in turn interacts with the operating system, which is a part of the system software layer.
The system software provides the direct interaction with the hard ware. The opening at the bottom
of the figure is the path followed by the user who interacts directly with the operating system
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
whennecessary.
COMPUTING ENVIRONMENTS
The word ‗compute‘ is used to refer to the process of converting information to data. The
advent of several new kinds of computers created a need to have different computing environments.
The following are the different kinds of computing environments available
1. Personal ComputingEnvironment
2. Time Sharing Environment
3. Client/ServerEnvironment
4. Distributed ComputingEnvironment
Personal Computing Environment
In 1971, Marcian E. Hoff, working for INTEL combined the basic elements of the central
processing unit into the microprocessor. If we are using a personal computer then all the computer
hardware components are tied together. This kind of computing is used to satisfy the needs of a
single user, who uses the computer for the personal tasks.
Ex: Personal Computer
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
Time-Sharing Environment
The concept of time sharing computing is to share the processing of the computer basing on
the criteria time. In this environment all the computing must be done by the central computer.
The complete processing is done by the central computer. The computer which ask for processing
are only dumbterminals.
Client/Server Environment
A Client/Server Computing involves the processing between two machines. A client
Machine is the one which requests processing. Server Machine is the one which offers the
processing. Hence the client is Capable enough to do processing. A portion of processing is done
by client and the core(important) processing is done byServer.
Distributed Computing
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
A distributed computing environment provides a seamless integration of computing
functions between different servers and clients. A client not just a requestor for processing the
information from the server. The client also has the capability to process information. All the
machines Clients/Servers share the
processing task.
COMPUTER LANGUAGES
To write a program (tells what to do) for a computer, we must use a computer language. Over
the years computer languages have evolved from machine languages to natural languages.
The following is the summary of computer languages
1940‘s -- Machine Languages
1950‘s -- Symbolic Languages
1960‘s -- High Level Languages
Machine Language
In the earliest days of computers, the only programming languages available were machine
languages. Each computer has its own machine language which is made of streams of 0‘s and 1‘s.
The instructions in machine language must be in streams of 0‘s and 1‘s. This is also referred as
binary digits. These are so named as the machine can directly understood the programs
Advantages:
1) High speedexecution
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
2) The computer can understood instructionsimmediately 3) No translation is
needed.
Disadvantages:
1) Machinedependent
2) Programming is verydifficult
3) Difficult tounderstand
4) Difficult to write bug freeprograms
5) Difficult to isolate anerror
Example Additon of two numbers
2 →0010
+ 3 →0011
5 0101
JAVA Object oriented language for internet and general applications using basic C syntax
Advantages:
1) Easy to write andunderstand
2) Easy to isolate anerror
3) Machine independentlanguage
4) Easy tomaintain
5) Better readability
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
6) Low Development cost
7) Easier todocument
8) Portable Disadvantages:
1) Needstranslator
2) Requires high executiontime
3) Poor control onhardware
4) Less efficient
Example: C language
#include<stdio.h> void
main()
{
int a,b,c;
scanf("%d%d%",&a,&b);
c=a+b; printf("%d",c);
}
Language Translators
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
These are the programs which are used for converting the programs in one language into
machine language instructions, so that they can be excuted by the computer.
COMPILER INTERPRETER
A Compiler is used to compile an entire program An interpreter is used to translate each line of the
and an executable program is generated through the program code immediately as it is entered
object program
The executable program is stored in a disk for The executable program is generated in RAM and
future use or to run it in another computer the interpreter is required for each run of the
program
The compiled programs run faster The Interpreted programs run slower
Most of the Languages use compiler A very few languages use interpreters.
COMPILER
(Error correction, memory
allocation, object code)
Library LINKE
R
RUNNER
(Execution,
exe. code)
OUTPUT
Compiling Programs
The code in a source file stored on the disk must be translated into machine language. This is
the job of the compiler. The Compiler is a computer program that translates the source code written
in a high-level language into the corresponding object code of the low-level language. This
translation process is called compilation. The entire high level program is converted into the
executable machine code file. The Compiler which executes C programs is called as C Compiler.
Example Turbo C, Borland C, GC etc., The C Compiler is actually two separate programs:
The Preprocessor
The Translator
The Preprocessor reads the source code and prepares it for the translator. While preparing the code,
it scans for special instructions known as preprocessor commands. These commands tell the
preprocessor to look for special code libraries. The result of preprocessing is called the
translationunit.
After the preprocessor has prepared the code for compilation, the translator does the actual
work of converting the program into machine language. The translator reads the translation unit and
writes the resulting object module to a file that can then be combined with other precompiled units
to form the final program. An object module is the code in the machine language.
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
Linking Programs
The Linker assembles all functions, the program‘s functions and system‘s functions into one
executable program.
Executing Programs
To execute a program we use an operating system command, such as run, to load the
program into primary memory and execute it. Getting the program into memory is the function
ofanoperatingsystemprogramknownastheloader.Itlocatestheexecutableprogramand
reads it into memory. When everything is loaded the program takes control and it begin execution.
ALGORITHM
Algorithm is a finite sequence of instructions, each of which has a clear meaning and can be
performed with a finite amount of effort in a finite length of time. No matter what the input values
may be, an algorithm terminates after executing a finite number of instructions.
We represent an algorithm using a pseudo language that is a combination of the constructs of a
programming language together with informal English statements.
The ordered set of instructions required to solve a problem is known as an algorithm.
The characteristics of a good algorithm are:
4Definiteness -
5 Effectiveness–
3 Finiteness – the algorithm stops after a finite number of instructions areexecuted. The
program must be terminated.
1 Input – the algorithm receives input.
2 Output – the algorithm must producesoutput.
Example
Q. Write a algorithem to find out number is odd or even?
Ans.
step 1 : start step 2 :
inputnumber step 3 :
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
rem=number mod 2 step 4 : if
rem=0then
print "number even"
else print "number odd"
endif
step 5 :stop
FLOWCHART
Flowchart is a diagrammatic representation of an algorithm. Flowchart is very helpful in writing
program and explaining program to others.
Symbols Used In Flowchart
Different symbols are used for different states in flowchart, For example: Input/Output and decision
making has different symbols. The table below describes all the symbols that are used in making
flowchart
Draw flowchart to find the largest among three different numbers entered by user.
1. Start: The program begins execution.
2. Declare Variables: The program declares three variables: 'a', 'b', and 'c'. These variables will
store the three input numbers.
3. Read a, b, and c: The program prompts the user to input three numbers, which are stored in the
corresponding variables 'a', 'b', and 'c'.
4. Is a > b? The program checks if 'a' is greater than 'b'.
o True: If 'a' is greater than 'b', the program proceeds to the next step.
o False: If 'a' is not greater than 'b', the program follows the path to the 'is b > c?' step.
5. Is b > c? (This step is reached only if 'a' is not greater than 'b' in the previous step). The program
checks if 'b' is greater than 'c'.
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
o True: If 'b' is greater than 'c', the program prints 'c'.
o False: If 'b' is not greater than 'c', the program follows the path to the 'is a > c?' step.
6. Is a > c? (This step is reached only if 'a' is greater than 'b' in the previous step). The program
checks if 'a' is greater than 'c'.
o True: If 'a' is greater than 'c', the program prints 'a'.
o False: If 'a' is not greater than 'c', the program prints 'b'.
7. Stop: The program ends execution after printing the largest number.
INTRODUCTION TO C LANGUAGE
C is a general-purpose high level language that was originally developed by Dennis Ritchie for the
Unix operating system. It was first implemented on the Digital Eqquipment Corporation PDP-11
computer in 1972.
The Unix operating system and virtually all Unix applications are written in the C language. C has
now become a widely used professional language for various reasons.
• Easy tolearn
• Structuredlanguage
• It produces efficientprograms.
• It can handle low-levelactivities.
• It can be compiled on a variety ofcomputers.
Facts about C
• C was invented to write an operating system calledUNIX.
HISTORY TO C LANGUAGE
C is a general-purpose language which has been closely associated with the UNIXoperating system
for which it was developed - since the system and most of the programs that run it are written in C.
Many of the important ideas of C stem from the language BCPL, developed by Martin Richards.
The influence of BCPL on C proceeded indirectly through the language B, which was written by
Ken Thompson in 1970 at Bell Labs, for the first UNIX system on a DECPDP- 7.
BCPL and B are "type less" languages whereas C provides a variety of datatypes.
In 1972 Dennis Ritchie at Bell Labs writes C and in 1978 the publication of The C
ProgrammingLanguage by Kernighan & Ritchie caused a revolution in the computing world. In
1983, the American National Standards Institute (ANSI) established a committee to provide a
modern, comprehensive definition of C. The resulting definition, the ANSI standard, or "ANSI C",
was completed late 1988.
1. Source Code: This is the original program written by the programmer in a high-level language.
It's human-readable but not directly understood by the computer.
2. Preprocessor: This step handles directives, such as #include and #define, that instruct the
compiler to include external code or define constants. It expands macros and prepares the code
for the next stage.
3. Compiler: The compiler translates the preprocessed source code into assembly language, which
is a low-level language closer to the computer's instruction set.
4. Assembly Code: This is the machine-readable code generated by the compiler. It's still not
directly executable by the computer.
5. Assembler: The assembler converts the assembly code into machine code, which is a series of
binary instructions that the computer can understand and execute.
6. Object Code: This is the machine code generated by the assembler. It's a partially compiled
program that might still need to be linked with other object files or libraries.
7. Libraries: These are collections of pre-compiled code that provide common functions and
routines used by programs.
8. Link Editor: The link editor combines the object code with any necessary libraries to create an
executable program. It resolves dependencies and creates a single file that can be run on the
computer.
9. Executable Code: This is the final program that can be executed by the computer. It contains all
the instructions and data needed to run the program.
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
C Compiler
The C compiler translates source to assembly code. The source code is received from the
preprocessor. Assembler
The assembler creates object code. On a UNIX system you may see files with a .o suffix
(.OBJ on MSDOS) to indicate object code files.
Link Editor
If a source file references library functions or functions defined in other source files the link editor
combines these functions (with main()) to create an executable file.
C TOKENS
C tokens are the basic buildings blocks in C language which are constructed together to write a C
program.
Each and every smallest individual unit in a C program is known as C tokens.
C tokens are of six types. They are
Keywords (eg: int,while),
Identifiers (eg: main,total),
Constants (eg: 10,20),
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
Strings (eg: ―total‖,―hello‖),
Special symbols (eg: (), {}),
Operators (eg: +, /,-,*)
C KEYWORDS
C keywords are the words that convey a special meaning to the c compiler. The keywords cannot
be used as variable names.
The list of C keywords is given below:
volatile while
C IDENTIFIERS
Identifiers are used as the general terminology for the names of variables, functions and arrays.
These are user defined names consisting of arbitrarily long sequence of letters and digits with either
a letter or the underscore(_) as a first character.
There are certain rules that should be followed while naming c identifiers:
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
They must begin with a letter or underscore (_).
They must consist of only letters, digits, or underscore. No other special character is allowed.
It should not be a keyword.
It must not contain whitespace.
It should be up to 31 characters long as only first 31 characters aresignificant.
Some examples of cidentifiers:
Name Remark
_A9 Valid
C CONSTANTS
A C constant refers to the data items that do not change their value during the program execution.
Several types of C constants that are allowed in C are:
Integer Constants
Integer constants are whole numbers without any fractional part. It must have at least one digit and
may contain either + or – sign. A number with no sign is assumed to be positive.
There are three types of integer constants:
Decimal Integer Constants
Integer constants consisting of a set of digits, 0 through 9, preceded by an optional – or + sign.
Example of valid decimal integer constants
341, -341, 0,8972
Octal Integer Constants
Integer constants consisting of sequence of digits from the set 0 through 7 starting with 0 is said to
be octal integer constants.
Example of valid octal integer constants
010, 0424, 0,0540
Hexadecimal Integer Constants
Hexadecimal integer constants are integer constants having sequence of digits preceded by 0x or 0X.
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
They may also include alphabets from A to F representing numbers 10 to 15.
Example of valid hexadecimal integer constants
0xD, 0X8d, 0X, 0xbD
It should be noted that, octal and hexadecimal integer constants are rarely used in programming.
Real Constants
The numbers having fractional parts are called real or floating point constants. These may be
represented in one of the two forms called fractional form or the exponent form and may also have
either + or – sign preceding it.
Example of valid real constants in fractional form or decimal notation
0.05, -0.905, 562.05, 0.015
Representing a real constant in exponent form
The general format in which a real number may be represented in exponential or scientific form is
mantissa e exponent
The mantissa must be either an integer or a real number expressed in decimal notation. The
letter e separating the mantissa and the exponent can also be written in uppercase i.e. E And,
the exponent must be an integer.
Examples of valid real constants in exponent form are:
252E85, 0.15E-10,-3e+8
Character Constants
A character constant contains one single character enclosed within single quotes.
Examples of valid character constants
‗a‘ , ‗Z‘,‗5‘
It should be noted that character constants have numerical values known as ASCII values, for
example, the value of ‗A‘ is 65 which is its ASCII value.
Escape Characters/ Escape Sequences
C allows us to have certain non graphic characters in character constants. Non graphic characters
are those characters that cannot be typed directly from keyboard, for example, tabs, carriage return,
etc.
These non graphic characters can be represented by using escape sequences represented by a
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
backslash() followed by one or more characters.
NOTE: An escape sequence consumes only one byte of space as it represents a single character.
a Audible alert(bell)
b Backspace
f Form feed
n New line
r Carriage return
t Horizontal tab
v Vertical tab
\ Backslash
? Question mark
Null
STRING CONSTANTS
String constants are sequence of characters enclosed within double quotes. For example,
―hello‖
―abc‖
―hello911‖
Everystingconstantisautomaticallyterminatedwithaspecialcharacter„‟calledthenull character
which represents the end of thestring.
For example, ―hello‖will represent ―hello‖in thememory.
Thus, the size of the string is the total number of characters plus one for the null character.
Special Symbols
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
The following special symbols are used in C having some special meaning and thus, cannot be used
for some other purpose.
[] () {} , ; : * … = #
Braces{}: These opening and ending curly braces marks the start and end of a block of code
containing more than one executable statement.
Parentheses(): These special symbols are used to indicate function calls and function parameters.
Brackets[]: Opening and closing brackets are used as array element reference. These indicate single
and multidimensional subscripts.
VARIABLES
A variable is nothing but a name given to a storage area that our programs can manipulate. Each
variable in C has a specific type, which determines the size and layout of the variable's memory; the
range of values that can be stored within that memory; and the set of operations that can be applied
to the variable.
The name of a variable can be composed of letters, digits, and the underscore character. It must
begin with either a letter or an underscore. Upper and lowercase letters are distinct because C is
case-sensitive. Based on the basic types explained in the previous chapter, there will be the
following basic variable types −
Type Description
Variable Definition in C
A variable definition tells the compiler where and how much storage to create for the variable. A
variable definition specifies a data type and contains a list of one or more variables of that type as
follows−
type variable_list;
Here, type must be a valid C data type including char, w_char, int, float, double, bool, or any user-
defined object; and variable_list may consist of one or more identifier names separated by commas.
Some valid declarations are shown here −
int i, j, k; char c, ch; float f,
salary; double d;
The line int i, j, k; declares and defines the variables i, j, and k; which instruct the compiler to
create variables named i, j and k of type int.
Variables can be initialized (assigned an initial value) in their declaration. The initializer consists of
an equal sign followed by a constant expression as follows−
Arithmetic_operators
These are used to perform mathematical calculations like addition, subtraction, multiplication, division
andmodulus
2
Assignment_operators
These are used to assign the values for the variables in C programs.
3
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
Relational operators
These operators are used to compare the value of two variables.
4 Logical operators
6 Conditional (ternary)operators
Conditional operators return one value if condition is true and returns another value is condition is false.
7 Increment/decrement operators
These operators are used to either increase or decrease the value of the variable by one.
8 Special operators
&, *, sizeof() and ternary operators.
ARITHMETIC OPERATORS IN C
C Arithmetic operators are used to perform mathematical calculations like addition, subtraction,
multiplication, division and modulus in C programs.
1 + Addition A+B
2 - Subtraction A-B
3 * multiplication A*B
4 / Division A/B
5 % Modulus A%B
#include <stdio.h>int
main()
OUTPUT:
Addition of a, b is : 60
Subtraction of a, b is : 20
Multiplication of a, b is : 800
Division of a, b is : 2
ASSIGNMENT OPERATORS IN C
of a, b is : %d\n", mod);
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Lipa Campus
A. Tanco Drive, Brgy. Marawoy, Lipa, Batangas, Philippines 4217
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94 loc. 3130
E-mail Address: cics.lipa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph