SlideShare a Scribd company logo
1 of 97
Syllabus
UNIT 1: Introduction to Computer, Programming & algorithms(8 L)
Introduction to components of a computer system (disks, memory,
processor, where a program is stored and executed, operating system,
compilers etc.)
Idea of Algorithm: steps to solve logical and numerical problems.
Representation of Algorithm: Flowchart/Pseudocode with examples,
From algorithms to programs; source code, variables (with data types)
variables and memory locations, Syntax and Logical Errors in
compilation, object and executable code
CSF101 – Programming for
Problem Solving
Unit – 1 Lecture – 1
Learning Objectives
In this Lecture you will learn
about:
Introduction to Computer
Characteristics of Computer
Basic operations of Computer systems
Basic components of Computer Systems
I/O devices
Introduction to Computer
• A computer is a programmable electronic
device designed to accept data, perform
prescribed mathematical and logical
operations at high speed, and display the
results of these operations.
• Desktops,laptops,tablets,and smartphones
are some of the different types of
computers.
Characteristics of Computer
• Automatic: Given a job, computer can work on it
automatically without human interventions
• Speed: Computer can perform data processing jobs
very fast, usually measured in microseconds (10-6),
nanoseconds (10-9), and picoseconds (10-12)
• Accuracy: Accuracy of a computer is consistently high
and the degree of its accuracy depends upon its
design.
Characteristics of Computer
• Diligence: Computer is free from monotony, tiredness, and
lack of concentration. It can continuously work for hours
without creating any error and without grumbling
• Versatility: Computer is capable of performing almost any
task, if the task can be reduced to a finite series of logical
steps
• Power of Remembering: Computer can store and recall any
amount of information because of its secondary storage
capability. It forgets or looses certain information only when
it is asked to do so
Basic operations of Computer
Systems
• Inputting. The process of entering data and instructions
into the computer system
• Storing. Saving data and instructions to make them
readily available for initial or additional processing
whenever required
• Processing. Performing arithmetic operations (add,
subtract, multiply, divide, etc.) or logical operations
(comparisons like equal to, less than, greater than, etc.)
on data to convert them into useful information
Basic operations of Computer
Systems
Outputting. The process of producing useful information
or results for the user such as a printed report or visual
display
Controlling. Directing the manner and sequence in which
all of the above operations are performed
Basic Components of
Computer Systems
Input Unit
An input unit of a computer system performs the
following functions:
1. It accepts (or reads) instructions and data from outside
world
2. It converts these instructions and data in computer
acceptable form
3. It supplies the converted instructions and data to the
computer system for further processing
Commonly Used Input
Devices
• Keyboard devices
• Point-and-draw devices
• Data scanning devices
• Digitizer
• Electronic cards based devices
• Speech recognition devices
• Vision based devices
Output Unit
An output unit of a computer system performs the
following functions:
1. It accepts the results produced by the computer, which
are in coded form and hence, cannot be easily
understood by us
2. It converts these coded results to human acceptable
(readable) form
3. It supplies the converted results to outside world
Commonly Used Output
Devices
• Monitors
• Printers
• Plotters
• Screen image projector
• Voice response systems
CSF101 – Programming for
Problem Solving
Unit – 1 Lecture – 2
Learning Objectives
In this Lecture you will learn
about:
Storage Unit: Primary and Secondary
Central Processing Unit
Hardware and Software
Classification of Software
Operating System
Storage Unit
The storage unit of a computer system holds (or
stores) the following :
1. Data and instructions required for processing
(received
from input devices)
2. Intermediate results of processing
3. Final results of processing, before they are released
to an output device
Two Types of storage
Primary storage/Main memory
• Every computer has a temporary storage built into
the computer hardware
• It stores instructions and data of a program mainly
when the program is being executed by the CPU.
• This temporary storage is known as main memory,
primary storage, or simply memory.
• It has random access property.
• Main memory is mostly volatile.
Random Access Memory and
Read Only Memory
• RAM: Primary storage of a computer is often
referred to as RAM because of its random access
capability. RAM chips are volatile memory
• ROM: It is a non-volatile memory chip. Data stored
in a ROM can only be read and used – they cannot
be changed. ROMs are mainly used to store
programs and data, which do not change and are
frequently used. For example, system boot
program
Two Types of storage
Secondary storage
 Used in a computer system to overcome the
limitations of primary storage
 Has virtually unlimited capacity because the cost per
bit of storage is very low
 Has an operating speed far slower than that
of the primary storage
 Used to store large volumes of data on a
permanent basis
 Also known as auxiliary memory
Classification of Commonly Used
Secondary Storage Devices
Property Desirable
Primary
storage
Secondary
storage
Storage
capacity
Large storage capacity Small Large
Access Time Fast access time Fast Slow
Cost per bit of
storage
Lower cost per bit High Low
Access Random access
Random
access
Pseudo-
random
access or
sequential
access
Storage Evaluation Criteria
21
Central Processing Unit
(CPU)
Arithmetic
Logic Unit
(ALU)
Control Unit
(CU)
=
Central
Processing
Unit (CPU)
• It is the brain of a computer system
• It is responsible for controlling the operations of all
other units of a computer system
• ALU: Arithmetic Logic Unit of a computer system is the
place where the actual executions of instructions takes
place during processing operation
• CU: Control Unit of a computer system manages and
coordinates the operations of all other components of
the computer system.
+
Hardware and Software
• Hardware refers to the physical components of a
computer. Computer Hardware is any part of the
computer that we can touch these parts. These are
the primary electronic devices used to build up the
computer. Examples of hardware in a computer are
the Processor, Memory , I/O devices, CPU etc.
• Software is a collection of instructions, procedures,
documentation that performs different tasks on a
computer system. Examples of software are Ms
Word, Excel, Power Point, Google Chrome,
Photoshop, MySQL etc.
Classification of Software
Software is broadly classified into two categories:
• System software is computer software designed to
operate the computer hardware, to provide basic
functionality, and to provide a platform for running
application software. System software includes device
drivers, operating systems, servers, utilities, compilers etc.
• Application software are the software that are designed
to satisfy a particular need of a particular environment.
Examples of application software railway reservation
software, income tax software, word processors etc.
Operating System
An operating system (OS) is
system software that manages
computer hardware, software
resources, and provides
common services for computer
programs.
Commonly used operating
systems are Windows, Linux, and
DOS.
CSF101 – Programming for
Problem Solving
Unit – 1 Lecture – 3
Learning Objectives
In this Lecture you will learn
about:
• Decimal number system
• Binary number system
• Octal number system
• Hexadecimal number system
• Conversion of Decimal number system to another
• Conversion of another number system to Decimal
Characteristics
 A positional number system
 Has 10 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7, 8,9).
Hence, its base = 10
 The maximum value of a single digit is 9 (one less than the
value of the base)
 Each position of a digit represents a
specific power of the base (10)
 We use this number system in
our day-to-day life
Example
258610 = (2 x 103) + (5 x 102) + (8 x 101) + (6 x 100)
= 2000 + 500 + 80 + 6
Decimal Number System
28
Characteristics
 A positional number system
 Has only 2 symbols or digits (0 and 1). base = 2
 The maximum value of a single digit is 1 (one less than the
value of the base)
 Each position of a digit represents a specific power of the
base (2)
 This number system is used in computers
Example
101012 = (1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) x (1 x 20)
= 16 + 0 + 4 + 0 + 1
= 2110
Binary Number System
29
 Bit stands for binary digit
 A bit in computer terminology means either a 0 or a 1
 A binary number consisting of n bits is called an n-bit number
 Group of 8 bit is referred as Byte.
Bit and Byte
30
Characteristics
 A positional number system
 Has total 8 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7). Hence, its
base = 8
 The maximum value of a single digit is 7 (one less than the
value of the base
 Each position of a digit represents a specific power of the base
(8)
 Since there are only 8 digits, 3 bits
(23 = 8) are sufficient to represent any octal
number in binary
Example
20578= (2 x 83) + (0 x 82) + (5 x 81) + (7 x 80)
= 1024 + 0 + 40 + 7=107110
Octal Number System
31
Characteristics
 A positional number system
 Has total 16 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F).
Hence its base = 16
 The symbols A, B, C, D, E and F represent the decimal values 10,
11, 12, 13, 14 and 15 respectively
 The maximum value of a single digit is 15 (one less than the value of
the base)
 Each position of a digit represents a specific power of the base (16)
 Since there are only 16 digits, 4 bits (24 = 16) are sufficient to represent
any hexadecimal number in binary
Example:
1AF16 = (1 x 16
2
) + (A x 16
1
) + (F x 16
0
)= 1 x 256 + 10 x 16 + 15 x 1
=256 + 160 + 15= 43110
Hexadecimal Number System
32
Converting a Number of Another Base to a
Decimal Number
Method
Step 1: Determine the column (positional) value of each digit
Step 2: Multiply the obtained column values by the digits in the
corresponding columns
Step 3: Calculate the sum of these products
Example
33
Division-Remainder Method
Step1: Divide the decimal number to be
converted by the value of the new base
Step 2: Record the remainder from Step 1 as the
rightmost digit (least significant digit) of
the new base number
Step3: Divide the quotient of the previous
divide by the new base
Converting a Decimal Number to
a Number of Another Base
Step 4: Record the remainder from Step 3 as the next digit
(to the left) of the new base number
Repeat Steps 3 and 4, recording remainders from right to left,
until the quotient becomes zero in Step 3
Note that the last remainder thus obtained will be the most
significant digit (MSD) of the new base number 34
Remainders
8 952
119
14
1
Example
95210 = ?8
Solution:
0
7
6
1
0
Hence, 95210 = 16708
35
CSF101 – Programming for
Problem Solving
Unit – 1 Lecture – 5
Learning Objectives
In this Lecture you will learn
about:
What is Programming, Data, Datatype, information,
Computer program?
How to solve a problem using computer
Algorithms
• Programming: Planning or scheduling the performance of
a task or an event
• Data: Information in a form a computer can use
• Information: Any knowledge that can be communicated
• Data type: The specification of how information is
represented in the computer as data and the set of
operations that can be applied to it
• Computer programming: The process of specifying the
data types and the operations for a computer to apply to
data in order to solve a problem
• Computer program: Data type specifications and
instructions for carrying out operations that are used by a
computer to solve a problem
How to solve a problem
using Computer?
To write a program for a computer to follow, we must
go through a two-phase process: problem solving and
implementation
Programming Process
Problem-Solving Phase
1. Analysis and Specification: Understand (define) the
problem and what the solution must do.
2. General Solution (Algorithm): Specify the required
data types and the logical sequences of steps that solve
the problem.
3. Verify: Follow the steps exactly to see if the solution
really does solve the problem.
How to solve a problem
using Computer?
How to solve a problem
using Computer?
Implementation Phase
1. Concrete Solution (Program): Translate the algorithm (the
general solution) into a programming language.
2. Test: Have the computer follow the instructions. Then
manually check the results. If you find errors, analyze the
program and the algorithm to determine the source of
the errors, and then make corrections.
Once a program has been written, it enters a third phase:
maintenance.
How to solve a problem
using Computer?
Maintenance Phase
1. Use: Use the program.
2. Maintain: Modify the program to meet changing
requirements or to correct any errors that show up
while using it.
Algorithm
 An algorithm is a finite set of Instructions for solving a particular
problem in a finite amount of time using a finite amount of data.
 In order to qualify as an algorithm, a sequence of instructions must
have following characteristics:
• Each and every instruction should be precise and unambiguous
• Each instruction should be such that it can be performed in a
finite time
• One or more instructions should not be repeated infinitely.
• This ensures that the algorithm will ultimately terminate
• After performing the instructions, that is after the algorithm
terminates, the desired results must be obtained
 Algorithm can be represented as programs, flowcharts and pseudo-
codes.
Sample Algorithm(Example 1)
Write an algorithm to find sum of two numbers.
Algorithm:
Step 1: Read two numbers in variable num1 and num2
Step 2: Add num1 and num2 and
sum=num1+num2
Step 3: Display result sum
Sample Algorithm(Example 2)
There are 100 employees in an organization. The organization wants to
distribute annual bonus to the employees based on their performance.
The performance of the employees is recorded in their annual
appraisal forms. Every employee’s appraisal form contains his/her basic
salary and the grade for his/her performance during the year. The
grade is of three categories – ‘A’ for outstanding performance, ‘B’ for
good performance, and ‘C’ for average performance. It has been
decided that the bonus of an employee will be 100% of the basic salary
for outstanding performance, 70% of the basic salary for good
performance, 40% of the basic salary for average performance, and
zero for all other cases. Write an algorithm to calculate and print the
total bonus amount to be distributed by the organization.
Sample Algorithm(Example 2)
Step 1: Initialize Total_Bonus and Total_Employees_Checked to zero.
Step 2: Initialize Bonus and Basic_Salary to zero.
Step 3: Take the appraisal form of the next employee.
Step 4: Read the employee’s Basic_Salary and Grade.
Step 5: If Grade = A, then Bonus = Basic_Salary. Go to Step 8.
Step 6: If Grade = B, then Bonus = Basic_Salary x 0.7. Go to Step 8.
Step 7: If Grade = C, then Bonus = Basic_Salary x 0.4.
Step 8: Add Bonus to Total_Bonus.
Step 9: Add 1 to Total_Employees_Checked.
Step 10: If Total_Employees_Checked < 100, then go to Step 2.
Step 11: Print Total_Bonus.
CSF101 – Programming for
Problem Solving
Unit – 1 Lecture – 5
Learning Objectives
In this Lecture you will learn
about:
Representation of Algorithms: Flowchart
Flowchart
• Flowchart is a pictorial representation of an algorithm
• Uses symbols (boxes of different shapes) that have standardized
meanings to denote different types of instructions
• Actual instructions are written within the boxes
• Boxes are connected by solid lines having arrow marks to indicate
the exact sequence in which the instructions are to be executed
• Process of drawing a flowchart for an algorithm is called
flowcharting
Basic Flow Chart Symbols
Examples of Decision Symbol
Is I = 10?
No
Yes
(a) A two-way branch decision. (b) A three-way branch decision.
A > B
A = B
A < B Compare
A & B
Sample Flowchart (Example 3)
A student appears in an examination, which consists of total
10 subjects, each subject having maximum marks of 100.
The roll number of the student, his/her name, and the marks
obtained by him/her in various subjects are supplied as input
data.
Such a collection of related data items, which is treated as a
unit is known as a record.
Draw a flowchart for the algorithm to calculate the percentage
marks obtained by the student in this examination and then to
print it along with his/her roll number and name.
Start
Read input data
Add marks of all
subjects giving Total
Percentage = Total / 10
Write output data
Stop
Sample Flowchart (Example 3)
(contd…)
start
50 students of a class appear in the examination of
Example 3.
Draw a flowchart for the algorithm to calculate and print
the percentage marks obtained by each student along
with his/her roll number and name.
Sample Flowchart (Example 4)
Flowchart for the solution
of Example 4 with an
infinite (endless) process
loop.
Start
Add marks of all
subjects giving Total
Percentage = Total / 10
Write output data
Read input data
Sample Flowchart (Example 4)
Flowchart for the solution
of Example 4.
Read input data
Count = 0
Add marks of all subjects giving Total
Percentage = Total/10
Write output data
Add 1 to Count
No
Is Count = 50?
Yes
Stop
Sample Flowchart (Example 4)
Start
 Better Communication
 Proper program documentation
 Efficient coding
 Systematic debugging
 Systematic testing
Advantages of Flowchart
 Flowcharts are very time consuming and
laborious to draw (especially for large
complex programs)
 Redrawing a flowchart for incorporating
changes/ modifications is a tedious task
 There are no standards determining the amount
of detail that should be included in a flowchart
Limitations of Flowchart
CSF101 – Programming for
Problem Solving
Unit – 1 Lecture – 6
Learning Objectives
In this Lecture you will learn
about:
Representation of Algorithms: Pseudo-code
Pseudo-code
 A program planning tool where program logic is
written in an ordinary natural language using a
structure that resembles computer instructions
 “ Pseudo” means imitation or false and “ Code”
refers to the instructions written in a programming
language. Hence, pseudocode is an imitation of
actual computer instructions
 Because it emphasizes the design of the program,
pseudocode is also called Program Design
Language (PDL)
62
Basic Logic (Control) Structures
Any program logic can be expressed by using only
following three simple logic structures:
1. Sequence logic,
2. Selection logic, and
3. Iteration (or looping) logic
Programs structured by using only these three logic
structures are called structured programs, and the
technique of writing such programs is known as structured
programming
63
It is used for performing instructions one after another
in sequence.
Sequence Logic
Process 1
(b) Pseudocode
Process 2
Process 1
Process 2
(a) Flowchart
64
Selection Logic
• Also known as decision logic, it is used for making
decisions
• Two popularly used selection logic structures are
1. IF…THEN…ELSE
2. IF…THEN
65
(b) Pseudocode
THEN
ENDIF
IF Condition
Process 1
THEN
Process 1
Yes No
(a) Flowchart
Selection Logic (IF…THEN Structure)
IF (condition)
66
Selection Logic (IF…THEN…ELSE Structure)
THEN
ELSE
Process 1
Process 2
IF Condition
ENDIF
(b) Pseudocode
THEN
Process 1
ELSE
Process 2
Yes No
(a) Flowchart
IF (condition)
67
Iteration (or Looping) Logic
 Used to produce loops in program logic when one or
more instructions may be executed several times
depending on some conditions
 Two popularly used iteration logic structures are
1. DO…WHILE
2. REPEAT…UNTIL
68
Iteration (or Looping) Logic
(DO…WHILE Structure)
(b) Pseudocode
DO WHILE Condition
Process 1
Process n
ENDDO
Process 1
False
(a) Flowchart
Process n
True
Condition?
Block
69
Iteration (or Looping) Logic
(REPEAT…UNTIL Structure)
(b) Pseudocode
REPEAT
Process 1
Process n
UNTIL Condition
Process 1
Process n
True
(a) Flowchart
False
Condition?
70
Suppose the input data of each student for the
examination of Example 3 also contains information
regarding the gender of the candidate in the field named
Gendercode having values M (for male) or F (for female).
We want to make a list of only those female students who
have passed in second division (obtained 45% or more but
less than 60% marks).
In the end, we also want to print out the total number of
such students.
Assuming that the input data of all the students is
terminated by a trailer record, which has a sentinel value
of Z for Gendercode,Write a pseudo code for this.
Sample Pseudo-code (Example 5)
71
Sample Pseudo-code (for Example 5)
Set Count to zero
Read first student record
DO WHILE Gendercode is not equal
to Z IF Gendercode = F THEN
Calculate Percentage
IF Percentage = > 45 THEN
IF Percentage < 60 THEN
Write output data
Add 1 to Count
ENDIF
ENDIF
ENDIF
Read next student record
ENDDO
Write Count
Stop
Advantages of Pseudocode
 Converting a pseudo-code to a programming
language is much more easier than converting a
flowchart to a programming language
 As compared to a flowchart, it is easier to modify the
pseudo-code of a program logic when program
modifications are necessary
 Writing of pseudo-code involves much less time and
effort than drawing an equivalent flowchart as it has
only a few rules to follow
73
Limitations of Pseudocode
 In case of pseudocode, a graphic representation of
program logic is not available
 There are no standard rules to follow in using
pseudocode
 Different programmers use their own style of
writing pseudocode and hence communication
problem occurs due to lack of standardization
 For a beginner, it is more difficult to follow the logic
of or write pseudocode, as compared to
flowcharting
74
CSF101 – Programming for
Problem Solving
Unit – 1 Lecture – 7
Learning Objectives
In this Lecture you will learn
about:
Introduction to Programming Languages
How Program is converted into a form that a
computer can use
Compilation and Execution
Types of Errors in Programming
Introduction to Programming
Language
A programming language is a simplified form of English (with
math symbols) that adheres to a strict set of grammatical rules.
English is far too complicated and ambiguous for today’s
computers to follow. Programming languages, because they limit
vocabulary and grammar, are much simpler .
Translating an algorithm into a programming language is called
coding the algorithm. The products of the translation—the code
for all the algorithms in the problem are tested by collecting
them into a program and running (executing) the program on
the computer. If the program fails to produce the desired
results, the programmer must debug it—that is, determine what
is wrong and then modify the program, or even one or more of
the algorithms, to fix it. The combination of coding and testing
the algorithms is called implementation.
How Is a Program Converted into a
Form That a Computer Can Use?
• In the computer, all data, whatever its form, is stored and used in
binary codes, strings of 1s and 0s. Instructions and data are stored
together in the computer’s memory using these binary codes.
• When computers were first developed, the only programming
language available was the primitive instruction set built into each
machine, the machine language, or machine code.
• Since Machine language was tough for programmers then assembly
language was developed. Instructions in an assembly language are in
an easy-to-remember form called a mnemonic (pronounced “ni- ‘
män – ik”). Typical instructions for addition and subtraction might
look like this:
Assembly Language Machine Language
ADD 100101
SUB 010011
• Although assembly language is easier for humans to work with,
the computer cannot directly execute the instructions. Because a
computer can process its own instructions as a form of data, it is
possible to write a program to translate assembly language
into machine code. Such a program is called an assembler.
• Assembly language is a step in the right direction, but it still forces
programmers to think in terms of individual machine instructions.
Eventually, computer scientists developed high-level programming
languages. These languages are easier to use than assembly
languages or machine code because they are closer to English and
other natural languages.
• A program called a compiler translates algorithms written in
certain high-level languages (Visual Basic, C++, Java, Pascal, and
Ada, for example) into machine language.
• The text of an algorithm written in a high-level language is
called source code. To the compiler, source code is just input
data. It translates the source code into a machine language
which is called object code .
• Following figure shows levels of abstraction for programming
languages.
Compilation and Execution
It is important to understand
that compilation and execution
are two distinct processes.
During compilation, the
computer runs the compiler
program. During execution, the
object program is loaded into
the computer’s memory unit,
replacing the compiler
program. The computer then
directly executes the object
program, doing whatever the
program instructs it to do. See
the figure.
Types of Programming Errors
Programming errors are broadly classified into four
categories:
• Syntax error/Compile-time error: Errors that occur when
you violate the rules of writing Programming syntax are
known as syntax errors. This compiler error indicates
something that must be fixed before the code can be
compiled. All these errors are detected by compiler and
thus are known as compile-time errors.
• Run-time error: Errors which occur during program
execution(run-time) after successful compilation are
called run-time errors. One of the most common run-time
error is division by zero also known as Division error.
These types of error are hard to find as the compiler
doesn’t point to the line at which the error occurs.
Types of Programming Errors
Logical Errors: On compilation and execution of a
program, desired output is not obtained when
certain input values are given. These types of errors
which provide incorrect output but appears to be
error free are called logical errors.
Semantic Errors:This error occurs when the
statements written in the program are not
meaningful to the compiler.
CSF101 – Programming for
Problem Solving
Unit – 1 Lecture – 8
Learning Objectives
In this Lecture you will learn
about:
• Introduction to C Programming Language
• Variables, Data types, Identifiers, Keywords
• First C Program, Compilation and Execution
Introduction to C Programming
Language
86
• C is a programming language developed at AT & T’s Bell
Laboratories of USA in 1972. It was designed and written
by a man named Dennis Ritchie.
• It incorporates properties of High Level language as well
as low level language.
• It is a structured programming language.
• C is a Case-Sensitive language. For example: int and INT
are two different words.
C Character Sets
87
A character denotes any alphabet, digit or special symbol used to
represent information. Following Figure shows the valid alphabets,
numbers and special symbols allowed in C.
Identifiers
88
Identifier refers to name given to entities such as variables, functions,
structures etc. Identifiers must be unique. They are created to give a
unique name to an entity to identify it during the execution of the
program.
Rules for naming identifiers:
• A valid identifier can have letters (both uppercase and lowercase
letters), digits and underscores.
• The first letter of an identifier should be either a letter or an
underscore.
• You cannot use keywords as identifiers.
• There is no rule on how long an identifier can be. However, you
may run into problems in some compilers if the identifier is longer
than 31 characters.
Examples:
abc, _abc, abc123
Keywords
89
Keywords are predefined, reserved words used in
programming that have special meanings to the compiler.
Keywords are part of the syntax and they cannot be used
as an identifier. C having 32 predefined keywords.
Variables
90
• A variable is a name given to memory location. Basically, a variable
is used to store some form of data. Different types of variables
require different amounts of memory, and have some specific set of
operations which can be applied on them.
• A variable must be declared before use in the program.
• Syntax for declaring a variable in C:
datatype variable_name;
datatype tells the type of variable and variable_name is a valid
identifier name.
Example: int x;
In this example x is a variable which is going to store integer data type.
Data Types
91
Each variable in C has an associated data type. Each data
type requires different amounts of memory and has some
specific operations which can be performed over it. Data
type is classified into two categories:
1. Primitive/Fundamental data type: some very common
data types are int, char, float, double, long etc.
2. Derived data type: Data types that are derived from
fundamental data types are derived types. For example:
arrays, pointers, function types, structures, etc.
Description of common primitive data
types
92
Data Type Used For Memory(Turbo
C compiler)
int Integer data 2 bytes
char Character data 1 byte
float Real numbers data with
single precision floating
point
4 bytes
double Real numbers data with
double precision floating
point
8 bytes
long Long integer data 4 bytes
unsigned Positive integer data 2 bytes
First C Program
93
Following rules that are applicable to all C programs:
• Each instruction in a C program is written as a separate
statement. Therefore a complete C program would comprise of
a series of statements.
• The statements in a program must appear in the same order in
which we wish them to be executed; unless of course the logic
of the problem demands a deliberate ‘jump’ or transfer of
control to a statement, which is out of sequence.
• Blank spaces may be inserted between two words to improve
the readability of the statement. However, no blank spaces are
allowed within a variable, constant or keyword.
• All statements should be entered in small case letters.
• C has no specific rules for the position at which a statement is
to be written. That’s why it is often called a free-form
language.
• Every C statement must end with a ;. Thus ; acts as a statement
terminator.
Printing Hello World on Screen
94
/* Printing Hello World*/
#include<stdio.h>
void main( )
{
printf(“hello world”);
}
Comment
Preprocessor directive which is
required to call printf function
This is main function definition.
Program execution starts from
here.
Call of printf function to display
“hello world” on screen
Compilation and Execution
95
• Once you have written the program you need to type it
and instruct the machine to execute it. To type your C
program you need another program called Editor.
• There are several such IDEs available in the market
targeted towards different operating systems. For
example, Turbo C, Turbo C++ and Microsoft C are some of
the popular compilers that work under MS-DOS; Visual
C++ and Borland C++ are the compilers that work under
Windows, whereas gcc compiler works under Linux.
Compilation and Execution
96
Assuming that you are using a Turbo C or Turbo C++
compiler. Here are the steps that you need to follow to
compile and execute your first C program.
• Start the compiler at C> prompt. The compiler (TC.EXE is
• usually present in C:TCBIN directory).
• Select New from the File menu.
• Type the program.
• Save the program using F2 under a proper name (say
• Program1.c).
• Use Ctrl + F9 to compile and execute the program.
• Use Alt + F5 to view the output.
REFERENCES
97
• Sinha, P. K., & Sinha, P. BPB Publication. Computer
Fundamental, Third Edition-2005, 12.
• Kanetkar, Y. P. (2016). Let us C. BPB publications.
• Overview of programming and problem solving by
mcmillan computer science series.
http://computerscience.jbpub.com/vbnet/pdfs/mcmilla
n01.pdf

More Related Content

Similar to Unit-1 CSF101- Programming for Problem Solving (1).pptx

Introduction To Computer Systems
Introduction To Computer SystemsIntroduction To Computer Systems
Introduction To Computer SystemsNaheed Azam
 
Computer Fundamentals lecture 1 Basic components of computer system.pptx
Computer Fundamentals lecture 1 Basic components of computer system.pptxComputer Fundamentals lecture 1 Basic components of computer system.pptx
Computer Fundamentals lecture 1 Basic components of computer system.pptxdbmscse61
 
Hardware and software of computer
Hardware and software of computerHardware and software of computer
Hardware and software of computerSurath Khadka
 
Computer Architecture and Organization.pptx
Computer Architecture and Organization.pptxComputer Architecture and Organization.pptx
Computer Architecture and Organization.pptxLearnersCoach
 
diploma basic of computers.ppt
diploma basic of computers.pptdiploma basic of computers.ppt
diploma basic of computers.pptLathaSrinivas5
 
Intro to Computing Lec 1.pptx
Intro to Computing Lec 1.pptxIntro to Computing Lec 1.pptx
Intro to Computing Lec 1.pptxFalakNiaz15
 
Computer Hardware and Software Elements
Computer Hardware and Software ElementsComputer Hardware and Software Elements
Computer Hardware and Software ElementsAdetula Bunmi
 
Computer Fundamentals.pptx
Computer Fundamentals.pptxComputer Fundamentals.pptx
Computer Fundamentals.pptxJaimeCanchela1
 
Computer Organization and Architecture.pptx
Computer Organization and Architecture.pptxComputer Organization and Architecture.pptx
Computer Organization and Architecture.pptxAshokRachapalli1
 
An Introduction To Python - Understanding Computers
An Introduction To Python - Understanding ComputersAn Introduction To Python - Understanding Computers
An Introduction To Python - Understanding ComputersBlue Elephant Consulting
 
Basics of computers.pptx
Basics of computers.pptxBasics of computers.pptx
Basics of computers.pptx123mengie
 
Understanding Computers - Today and Tomorrow
Understanding Computers - Today and TomorrowUnderstanding Computers - Today and Tomorrow
Understanding Computers - Today and TomorrowGufranAhmadJU
 
Intro_to_Computers_Parts.ppt
Intro_to_Computers_Parts.pptIntro_to_Computers_Parts.ppt
Intro_to_Computers_Parts.pptSylvesterNdegese1
 
Module-1_Part_1 (1).pptx
Module-1_Part_1 (1).pptxModule-1_Part_1 (1).pptx
Module-1_Part_1 (1).pptxkumarloresh143
 
Basic Computer Skills.pptx
Basic Computer Skills.pptxBasic Computer Skills.pptx
Basic Computer Skills.pptxssuser504dda
 
Unit-I - Introduction to Computer Fundamentals-AWI-.pptx
Unit-I - Introduction to Computer Fundamentals-AWI-.pptxUnit-I - Introduction to Computer Fundamentals-AWI-.pptx
Unit-I - Introduction to Computer Fundamentals-AWI-.pptxMrNikhilMohanShinde
 

Similar to Unit-1 CSF101- Programming for Problem Solving (1).pptx (20)

Introduction To Computer Systems
Introduction To Computer SystemsIntroduction To Computer Systems
Introduction To Computer Systems
 
Computer Fundamentals lecture 1 Basic components of computer system.pptx
Computer Fundamentals lecture 1 Basic components of computer system.pptxComputer Fundamentals lecture 1 Basic components of computer system.pptx
Computer Fundamentals lecture 1 Basic components of computer system.pptx
 
Hardware and software of computer
Hardware and software of computerHardware and software of computer
Hardware and software of computer
 
Computer Architecture
Computer ArchitectureComputer Architecture
Computer Architecture
 
Computer Architecture and Organization.pptx
Computer Architecture and Organization.pptxComputer Architecture and Organization.pptx
Computer Architecture and Organization.pptx
 
diploma basic of computers.ppt
diploma basic of computers.pptdiploma basic of computers.ppt
diploma basic of computers.ppt
 
Intro to Computing Lec 1.pptx
Intro to Computing Lec 1.pptxIntro to Computing Lec 1.pptx
Intro to Computing Lec 1.pptx
 
Computer Hardware and Software Elements
Computer Hardware and Software ElementsComputer Hardware and Software Elements
Computer Hardware and Software Elements
 
Computer Fundamentals.pptx
Computer Fundamentals.pptxComputer Fundamentals.pptx
Computer Fundamentals.pptx
 
Computer Organization and Architecture.pptx
Computer Organization and Architecture.pptxComputer Organization and Architecture.pptx
Computer Organization and Architecture.pptx
 
An Introduction To Python - Understanding Computers
An Introduction To Python - Understanding ComputersAn Introduction To Python - Understanding Computers
An Introduction To Python - Understanding Computers
 
Basics of computers.pptx
Basics of computers.pptxBasics of computers.pptx
Basics of computers.pptx
 
Understanding Computers - Today and Tomorrow
Understanding Computers - Today and TomorrowUnderstanding Computers - Today and Tomorrow
Understanding Computers - Today and Tomorrow
 
Computer Introduction
Computer IntroductionComputer Introduction
Computer Introduction
 
Intro_to_Computers_Parts.ppt
Intro_to_Computers_Parts.pptIntro_to_Computers_Parts.ppt
Intro_to_Computers_Parts.ppt
 
Module-1_Part_1 (1).pptx
Module-1_Part_1 (1).pptxModule-1_Part_1 (1).pptx
Module-1_Part_1 (1).pptx
 
Lecture2.pptx
Lecture2.pptxLecture2.pptx
Lecture2.pptx
 
Basic Computer Skills.pptx
Basic Computer Skills.pptxBasic Computer Skills.pptx
Basic Computer Skills.pptx
 
Computer System.pptx
Computer System.pptxComputer System.pptx
Computer System.pptx
 
Unit-I - Introduction to Computer Fundamentals-AWI-.pptx
Unit-I - Introduction to Computer Fundamentals-AWI-.pptxUnit-I - Introduction to Computer Fundamentals-AWI-.pptx
Unit-I - Introduction to Computer Fundamentals-AWI-.pptx
 

Recently uploaded

CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 

Recently uploaded (20)

CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 

Unit-1 CSF101- Programming for Problem Solving (1).pptx

  • 1. Syllabus UNIT 1: Introduction to Computer, Programming & algorithms(8 L) Introduction to components of a computer system (disks, memory, processor, where a program is stored and executed, operating system, compilers etc.) Idea of Algorithm: steps to solve logical and numerical problems. Representation of Algorithm: Flowchart/Pseudocode with examples, From algorithms to programs; source code, variables (with data types) variables and memory locations, Syntax and Logical Errors in compilation, object and executable code
  • 2. CSF101 – Programming for Problem Solving Unit – 1 Lecture – 1
  • 3. Learning Objectives In this Lecture you will learn about: Introduction to Computer Characteristics of Computer Basic operations of Computer systems Basic components of Computer Systems I/O devices
  • 4. Introduction to Computer • A computer is a programmable electronic device designed to accept data, perform prescribed mathematical and logical operations at high speed, and display the results of these operations. • Desktops,laptops,tablets,and smartphones are some of the different types of computers.
  • 5. Characteristics of Computer • Automatic: Given a job, computer can work on it automatically without human interventions • Speed: Computer can perform data processing jobs very fast, usually measured in microseconds (10-6), nanoseconds (10-9), and picoseconds (10-12) • Accuracy: Accuracy of a computer is consistently high and the degree of its accuracy depends upon its design.
  • 6. Characteristics of Computer • Diligence: Computer is free from monotony, tiredness, and lack of concentration. It can continuously work for hours without creating any error and without grumbling • Versatility: Computer is capable of performing almost any task, if the task can be reduced to a finite series of logical steps • Power of Remembering: Computer can store and recall any amount of information because of its secondary storage capability. It forgets or looses certain information only when it is asked to do so
  • 7. Basic operations of Computer Systems • Inputting. The process of entering data and instructions into the computer system • Storing. Saving data and instructions to make them readily available for initial or additional processing whenever required • Processing. Performing arithmetic operations (add, subtract, multiply, divide, etc.) or logical operations (comparisons like equal to, less than, greater than, etc.) on data to convert them into useful information
  • 8. Basic operations of Computer Systems Outputting. The process of producing useful information or results for the user such as a printed report or visual display Controlling. Directing the manner and sequence in which all of the above operations are performed
  • 10. Input Unit An input unit of a computer system performs the following functions: 1. It accepts (or reads) instructions and data from outside world 2. It converts these instructions and data in computer acceptable form 3. It supplies the converted instructions and data to the computer system for further processing
  • 11. Commonly Used Input Devices • Keyboard devices • Point-and-draw devices • Data scanning devices • Digitizer • Electronic cards based devices • Speech recognition devices • Vision based devices
  • 12. Output Unit An output unit of a computer system performs the following functions: 1. It accepts the results produced by the computer, which are in coded form and hence, cannot be easily understood by us 2. It converts these coded results to human acceptable (readable) form 3. It supplies the converted results to outside world
  • 13. Commonly Used Output Devices • Monitors • Printers • Plotters • Screen image projector • Voice response systems
  • 14. CSF101 – Programming for Problem Solving Unit – 1 Lecture – 2
  • 15. Learning Objectives In this Lecture you will learn about: Storage Unit: Primary and Secondary Central Processing Unit Hardware and Software Classification of Software Operating System
  • 16. Storage Unit The storage unit of a computer system holds (or stores) the following : 1. Data and instructions required for processing (received from input devices) 2. Intermediate results of processing 3. Final results of processing, before they are released to an output device
  • 17. Two Types of storage Primary storage/Main memory • Every computer has a temporary storage built into the computer hardware • It stores instructions and data of a program mainly when the program is being executed by the CPU. • This temporary storage is known as main memory, primary storage, or simply memory. • It has random access property. • Main memory is mostly volatile.
  • 18. Random Access Memory and Read Only Memory • RAM: Primary storage of a computer is often referred to as RAM because of its random access capability. RAM chips are volatile memory • ROM: It is a non-volatile memory chip. Data stored in a ROM can only be read and used – they cannot be changed. ROMs are mainly used to store programs and data, which do not change and are frequently used. For example, system boot program
  • 19. Two Types of storage Secondary storage  Used in a computer system to overcome the limitations of primary storage  Has virtually unlimited capacity because the cost per bit of storage is very low  Has an operating speed far slower than that of the primary storage  Used to store large volumes of data on a permanent basis  Also known as auxiliary memory
  • 20. Classification of Commonly Used Secondary Storage Devices
  • 21. Property Desirable Primary storage Secondary storage Storage capacity Large storage capacity Small Large Access Time Fast access time Fast Slow Cost per bit of storage Lower cost per bit High Low Access Random access Random access Pseudo- random access or sequential access Storage Evaluation Criteria 21
  • 22. Central Processing Unit (CPU) Arithmetic Logic Unit (ALU) Control Unit (CU) = Central Processing Unit (CPU) • It is the brain of a computer system • It is responsible for controlling the operations of all other units of a computer system • ALU: Arithmetic Logic Unit of a computer system is the place where the actual executions of instructions takes place during processing operation • CU: Control Unit of a computer system manages and coordinates the operations of all other components of the computer system. +
  • 23. Hardware and Software • Hardware refers to the physical components of a computer. Computer Hardware is any part of the computer that we can touch these parts. These are the primary electronic devices used to build up the computer. Examples of hardware in a computer are the Processor, Memory , I/O devices, CPU etc. • Software is a collection of instructions, procedures, documentation that performs different tasks on a computer system. Examples of software are Ms Word, Excel, Power Point, Google Chrome, Photoshop, MySQL etc.
  • 24. Classification of Software Software is broadly classified into two categories: • System software is computer software designed to operate the computer hardware, to provide basic functionality, and to provide a platform for running application software. System software includes device drivers, operating systems, servers, utilities, compilers etc. • Application software are the software that are designed to satisfy a particular need of a particular environment. Examples of application software railway reservation software, income tax software, word processors etc.
  • 25. Operating System An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. Commonly used operating systems are Windows, Linux, and DOS.
  • 26. CSF101 – Programming for Problem Solving Unit – 1 Lecture – 3
  • 27. Learning Objectives In this Lecture you will learn about: • Decimal number system • Binary number system • Octal number system • Hexadecimal number system • Conversion of Decimal number system to another • Conversion of another number system to Decimal
  • 28. Characteristics  A positional number system  Has 10 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7, 8,9). Hence, its base = 10  The maximum value of a single digit is 9 (one less than the value of the base)  Each position of a digit represents a specific power of the base (10)  We use this number system in our day-to-day life Example 258610 = (2 x 103) + (5 x 102) + (8 x 101) + (6 x 100) = 2000 + 500 + 80 + 6 Decimal Number System 28
  • 29. Characteristics  A positional number system  Has only 2 symbols or digits (0 and 1). base = 2  The maximum value of a single digit is 1 (one less than the value of the base)  Each position of a digit represents a specific power of the base (2)  This number system is used in computers Example 101012 = (1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) x (1 x 20) = 16 + 0 + 4 + 0 + 1 = 2110 Binary Number System 29
  • 30.  Bit stands for binary digit  A bit in computer terminology means either a 0 or a 1  A binary number consisting of n bits is called an n-bit number  Group of 8 bit is referred as Byte. Bit and Byte 30
  • 31. Characteristics  A positional number system  Has total 8 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7). Hence, its base = 8  The maximum value of a single digit is 7 (one less than the value of the base  Each position of a digit represents a specific power of the base (8)  Since there are only 8 digits, 3 bits (23 = 8) are sufficient to represent any octal number in binary Example 20578= (2 x 83) + (0 x 82) + (5 x 81) + (7 x 80) = 1024 + 0 + 40 + 7=107110 Octal Number System 31
  • 32. Characteristics  A positional number system  Has total 16 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F). Hence its base = 16  The symbols A, B, C, D, E and F represent the decimal values 10, 11, 12, 13, 14 and 15 respectively  The maximum value of a single digit is 15 (one less than the value of the base)  Each position of a digit represents a specific power of the base (16)  Since there are only 16 digits, 4 bits (24 = 16) are sufficient to represent any hexadecimal number in binary Example: 1AF16 = (1 x 16 2 ) + (A x 16 1 ) + (F x 16 0 )= 1 x 256 + 10 x 16 + 15 x 1 =256 + 160 + 15= 43110 Hexadecimal Number System 32
  • 33. Converting a Number of Another Base to a Decimal Number Method Step 1: Determine the column (positional) value of each digit Step 2: Multiply the obtained column values by the digits in the corresponding columns Step 3: Calculate the sum of these products Example 33
  • 34. Division-Remainder Method Step1: Divide the decimal number to be converted by the value of the new base Step 2: Record the remainder from Step 1 as the rightmost digit (least significant digit) of the new base number Step3: Divide the quotient of the previous divide by the new base Converting a Decimal Number to a Number of Another Base Step 4: Record the remainder from Step 3 as the next digit (to the left) of the new base number Repeat Steps 3 and 4, recording remainders from right to left, until the quotient becomes zero in Step 3 Note that the last remainder thus obtained will be the most significant digit (MSD) of the new base number 34
  • 35. Remainders 8 952 119 14 1 Example 95210 = ?8 Solution: 0 7 6 1 0 Hence, 95210 = 16708 35
  • 36. CSF101 – Programming for Problem Solving Unit – 1 Lecture – 5
  • 37. Learning Objectives In this Lecture you will learn about: What is Programming, Data, Datatype, information, Computer program? How to solve a problem using computer Algorithms
  • 38. • Programming: Planning or scheduling the performance of a task or an event • Data: Information in a form a computer can use • Information: Any knowledge that can be communicated • Data type: The specification of how information is represented in the computer as data and the set of operations that can be applied to it • Computer programming: The process of specifying the data types and the operations for a computer to apply to data in order to solve a problem • Computer program: Data type specifications and instructions for carrying out operations that are used by a computer to solve a problem
  • 39. How to solve a problem using Computer? To write a program for a computer to follow, we must go through a two-phase process: problem solving and implementation
  • 41. Problem-Solving Phase 1. Analysis and Specification: Understand (define) the problem and what the solution must do. 2. General Solution (Algorithm): Specify the required data types and the logical sequences of steps that solve the problem. 3. Verify: Follow the steps exactly to see if the solution really does solve the problem. How to solve a problem using Computer?
  • 42. How to solve a problem using Computer? Implementation Phase 1. Concrete Solution (Program): Translate the algorithm (the general solution) into a programming language. 2. Test: Have the computer follow the instructions. Then manually check the results. If you find errors, analyze the program and the algorithm to determine the source of the errors, and then make corrections. Once a program has been written, it enters a third phase: maintenance.
  • 43. How to solve a problem using Computer? Maintenance Phase 1. Use: Use the program. 2. Maintain: Modify the program to meet changing requirements or to correct any errors that show up while using it.
  • 44. Algorithm  An algorithm is a finite set of Instructions for solving a particular problem in a finite amount of time using a finite amount of data.  In order to qualify as an algorithm, a sequence of instructions must have following characteristics: • Each and every instruction should be precise and unambiguous • Each instruction should be such that it can be performed in a finite time • One or more instructions should not be repeated infinitely. • This ensures that the algorithm will ultimately terminate • After performing the instructions, that is after the algorithm terminates, the desired results must be obtained  Algorithm can be represented as programs, flowcharts and pseudo- codes.
  • 45. Sample Algorithm(Example 1) Write an algorithm to find sum of two numbers. Algorithm: Step 1: Read two numbers in variable num1 and num2 Step 2: Add num1 and num2 and sum=num1+num2 Step 3: Display result sum
  • 46. Sample Algorithm(Example 2) There are 100 employees in an organization. The organization wants to distribute annual bonus to the employees based on their performance. The performance of the employees is recorded in their annual appraisal forms. Every employee’s appraisal form contains his/her basic salary and the grade for his/her performance during the year. The grade is of three categories – ‘A’ for outstanding performance, ‘B’ for good performance, and ‘C’ for average performance. It has been decided that the bonus of an employee will be 100% of the basic salary for outstanding performance, 70% of the basic salary for good performance, 40% of the basic salary for average performance, and zero for all other cases. Write an algorithm to calculate and print the total bonus amount to be distributed by the organization.
  • 47. Sample Algorithm(Example 2) Step 1: Initialize Total_Bonus and Total_Employees_Checked to zero. Step 2: Initialize Bonus and Basic_Salary to zero. Step 3: Take the appraisal form of the next employee. Step 4: Read the employee’s Basic_Salary and Grade. Step 5: If Grade = A, then Bonus = Basic_Salary. Go to Step 8. Step 6: If Grade = B, then Bonus = Basic_Salary x 0.7. Go to Step 8. Step 7: If Grade = C, then Bonus = Basic_Salary x 0.4. Step 8: Add Bonus to Total_Bonus. Step 9: Add 1 to Total_Employees_Checked. Step 10: If Total_Employees_Checked < 100, then go to Step 2. Step 11: Print Total_Bonus.
  • 48. CSF101 – Programming for Problem Solving Unit – 1 Lecture – 5
  • 49. Learning Objectives In this Lecture you will learn about: Representation of Algorithms: Flowchart
  • 50. Flowchart • Flowchart is a pictorial representation of an algorithm • Uses symbols (boxes of different shapes) that have standardized meanings to denote different types of instructions • Actual instructions are written within the boxes • Boxes are connected by solid lines having arrow marks to indicate the exact sequence in which the instructions are to be executed • Process of drawing a flowchart for an algorithm is called flowcharting
  • 51. Basic Flow Chart Symbols
  • 52. Examples of Decision Symbol Is I = 10? No Yes (a) A two-way branch decision. (b) A three-way branch decision. A > B A = B A < B Compare A & B
  • 53. Sample Flowchart (Example 3) A student appears in an examination, which consists of total 10 subjects, each subject having maximum marks of 100. The roll number of the student, his/her name, and the marks obtained by him/her in various subjects are supplied as input data. Such a collection of related data items, which is treated as a unit is known as a record. Draw a flowchart for the algorithm to calculate the percentage marks obtained by the student in this examination and then to print it along with his/her roll number and name.
  • 54. Start Read input data Add marks of all subjects giving Total Percentage = Total / 10 Write output data Stop Sample Flowchart (Example 3) (contd…) start
  • 55. 50 students of a class appear in the examination of Example 3. Draw a flowchart for the algorithm to calculate and print the percentage marks obtained by each student along with his/her roll number and name. Sample Flowchart (Example 4)
  • 56. Flowchart for the solution of Example 4 with an infinite (endless) process loop. Start Add marks of all subjects giving Total Percentage = Total / 10 Write output data Read input data Sample Flowchart (Example 4)
  • 57. Flowchart for the solution of Example 4. Read input data Count = 0 Add marks of all subjects giving Total Percentage = Total/10 Write output data Add 1 to Count No Is Count = 50? Yes Stop Sample Flowchart (Example 4) Start
  • 58.  Better Communication  Proper program documentation  Efficient coding  Systematic debugging  Systematic testing Advantages of Flowchart
  • 59.  Flowcharts are very time consuming and laborious to draw (especially for large complex programs)  Redrawing a flowchart for incorporating changes/ modifications is a tedious task  There are no standards determining the amount of detail that should be included in a flowchart Limitations of Flowchart
  • 60. CSF101 – Programming for Problem Solving Unit – 1 Lecture – 6
  • 61. Learning Objectives In this Lecture you will learn about: Representation of Algorithms: Pseudo-code
  • 62. Pseudo-code  A program planning tool where program logic is written in an ordinary natural language using a structure that resembles computer instructions  “ Pseudo” means imitation or false and “ Code” refers to the instructions written in a programming language. Hence, pseudocode is an imitation of actual computer instructions  Because it emphasizes the design of the program, pseudocode is also called Program Design Language (PDL) 62
  • 63. Basic Logic (Control) Structures Any program logic can be expressed by using only following three simple logic structures: 1. Sequence logic, 2. Selection logic, and 3. Iteration (or looping) logic Programs structured by using only these three logic structures are called structured programs, and the technique of writing such programs is known as structured programming 63
  • 64. It is used for performing instructions one after another in sequence. Sequence Logic Process 1 (b) Pseudocode Process 2 Process 1 Process 2 (a) Flowchart 64
  • 65. Selection Logic • Also known as decision logic, it is used for making decisions • Two popularly used selection logic structures are 1. IF…THEN…ELSE 2. IF…THEN 65
  • 66. (b) Pseudocode THEN ENDIF IF Condition Process 1 THEN Process 1 Yes No (a) Flowchart Selection Logic (IF…THEN Structure) IF (condition) 66
  • 67. Selection Logic (IF…THEN…ELSE Structure) THEN ELSE Process 1 Process 2 IF Condition ENDIF (b) Pseudocode THEN Process 1 ELSE Process 2 Yes No (a) Flowchart IF (condition) 67
  • 68. Iteration (or Looping) Logic  Used to produce loops in program logic when one or more instructions may be executed several times depending on some conditions  Two popularly used iteration logic structures are 1. DO…WHILE 2. REPEAT…UNTIL 68
  • 69. Iteration (or Looping) Logic (DO…WHILE Structure) (b) Pseudocode DO WHILE Condition Process 1 Process n ENDDO Process 1 False (a) Flowchart Process n True Condition? Block 69
  • 70. Iteration (or Looping) Logic (REPEAT…UNTIL Structure) (b) Pseudocode REPEAT Process 1 Process n UNTIL Condition Process 1 Process n True (a) Flowchart False Condition? 70
  • 71. Suppose the input data of each student for the examination of Example 3 also contains information regarding the gender of the candidate in the field named Gendercode having values M (for male) or F (for female). We want to make a list of only those female students who have passed in second division (obtained 45% or more but less than 60% marks). In the end, we also want to print out the total number of such students. Assuming that the input data of all the students is terminated by a trailer record, which has a sentinel value of Z for Gendercode,Write a pseudo code for this. Sample Pseudo-code (Example 5) 71
  • 72. Sample Pseudo-code (for Example 5) Set Count to zero Read first student record DO WHILE Gendercode is not equal to Z IF Gendercode = F THEN Calculate Percentage IF Percentage = > 45 THEN IF Percentage < 60 THEN Write output data Add 1 to Count ENDIF ENDIF ENDIF Read next student record ENDDO Write Count Stop
  • 73. Advantages of Pseudocode  Converting a pseudo-code to a programming language is much more easier than converting a flowchart to a programming language  As compared to a flowchart, it is easier to modify the pseudo-code of a program logic when program modifications are necessary  Writing of pseudo-code involves much less time and effort than drawing an equivalent flowchart as it has only a few rules to follow 73
  • 74. Limitations of Pseudocode  In case of pseudocode, a graphic representation of program logic is not available  There are no standard rules to follow in using pseudocode  Different programmers use their own style of writing pseudocode and hence communication problem occurs due to lack of standardization  For a beginner, it is more difficult to follow the logic of or write pseudocode, as compared to flowcharting 74
  • 75. CSF101 – Programming for Problem Solving Unit – 1 Lecture – 7
  • 76. Learning Objectives In this Lecture you will learn about: Introduction to Programming Languages How Program is converted into a form that a computer can use Compilation and Execution Types of Errors in Programming
  • 77. Introduction to Programming Language A programming language is a simplified form of English (with math symbols) that adheres to a strict set of grammatical rules. English is far too complicated and ambiguous for today’s computers to follow. Programming languages, because they limit vocabulary and grammar, are much simpler . Translating an algorithm into a programming language is called coding the algorithm. The products of the translation—the code for all the algorithms in the problem are tested by collecting them into a program and running (executing) the program on the computer. If the program fails to produce the desired results, the programmer must debug it—that is, determine what is wrong and then modify the program, or even one or more of the algorithms, to fix it. The combination of coding and testing the algorithms is called implementation.
  • 78. How Is a Program Converted into a Form That a Computer Can Use? • In the computer, all data, whatever its form, is stored and used in binary codes, strings of 1s and 0s. Instructions and data are stored together in the computer’s memory using these binary codes. • When computers were first developed, the only programming language available was the primitive instruction set built into each machine, the machine language, or machine code. • Since Machine language was tough for programmers then assembly language was developed. Instructions in an assembly language are in an easy-to-remember form called a mnemonic (pronounced “ni- ‘ män – ik”). Typical instructions for addition and subtraction might look like this: Assembly Language Machine Language ADD 100101 SUB 010011
  • 79. • Although assembly language is easier for humans to work with, the computer cannot directly execute the instructions. Because a computer can process its own instructions as a form of data, it is possible to write a program to translate assembly language into machine code. Such a program is called an assembler. • Assembly language is a step in the right direction, but it still forces programmers to think in terms of individual machine instructions. Eventually, computer scientists developed high-level programming languages. These languages are easier to use than assembly languages or machine code because they are closer to English and other natural languages. • A program called a compiler translates algorithms written in certain high-level languages (Visual Basic, C++, Java, Pascal, and Ada, for example) into machine language.
  • 80. • The text of an algorithm written in a high-level language is called source code. To the compiler, source code is just input data. It translates the source code into a machine language which is called object code . • Following figure shows levels of abstraction for programming languages.
  • 81. Compilation and Execution It is important to understand that compilation and execution are two distinct processes. During compilation, the computer runs the compiler program. During execution, the object program is loaded into the computer’s memory unit, replacing the compiler program. The computer then directly executes the object program, doing whatever the program instructs it to do. See the figure.
  • 82. Types of Programming Errors Programming errors are broadly classified into four categories: • Syntax error/Compile-time error: Errors that occur when you violate the rules of writing Programming syntax are known as syntax errors. This compiler error indicates something that must be fixed before the code can be compiled. All these errors are detected by compiler and thus are known as compile-time errors. • Run-time error: Errors which occur during program execution(run-time) after successful compilation are called run-time errors. One of the most common run-time error is division by zero also known as Division error. These types of error are hard to find as the compiler doesn’t point to the line at which the error occurs.
  • 83. Types of Programming Errors Logical Errors: On compilation and execution of a program, desired output is not obtained when certain input values are given. These types of errors which provide incorrect output but appears to be error free are called logical errors. Semantic Errors:This error occurs when the statements written in the program are not meaningful to the compiler.
  • 84. CSF101 – Programming for Problem Solving Unit – 1 Lecture – 8
  • 85. Learning Objectives In this Lecture you will learn about: • Introduction to C Programming Language • Variables, Data types, Identifiers, Keywords • First C Program, Compilation and Execution
  • 86. Introduction to C Programming Language 86 • C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie. • It incorporates properties of High Level language as well as low level language. • It is a structured programming language. • C is a Case-Sensitive language. For example: int and INT are two different words.
  • 87. C Character Sets 87 A character denotes any alphabet, digit or special symbol used to represent information. Following Figure shows the valid alphabets, numbers and special symbols allowed in C.
  • 88. Identifiers 88 Identifier refers to name given to entities such as variables, functions, structures etc. Identifiers must be unique. They are created to give a unique name to an entity to identify it during the execution of the program. Rules for naming identifiers: • A valid identifier can have letters (both uppercase and lowercase letters), digits and underscores. • The first letter of an identifier should be either a letter or an underscore. • You cannot use keywords as identifiers. • There is no rule on how long an identifier can be. However, you may run into problems in some compilers if the identifier is longer than 31 characters. Examples: abc, _abc, abc123
  • 89. Keywords 89 Keywords are predefined, reserved words used in programming that have special meanings to the compiler. Keywords are part of the syntax and they cannot be used as an identifier. C having 32 predefined keywords.
  • 90. Variables 90 • A variable is a name given to memory location. Basically, a variable is used to store some form of data. Different types of variables require different amounts of memory, and have some specific set of operations which can be applied on them. • A variable must be declared before use in the program. • Syntax for declaring a variable in C: datatype variable_name; datatype tells the type of variable and variable_name is a valid identifier name. Example: int x; In this example x is a variable which is going to store integer data type.
  • 91. Data Types 91 Each variable in C has an associated data type. Each data type requires different amounts of memory and has some specific operations which can be performed over it. Data type is classified into two categories: 1. Primitive/Fundamental data type: some very common data types are int, char, float, double, long etc. 2. Derived data type: Data types that are derived from fundamental data types are derived types. For example: arrays, pointers, function types, structures, etc.
  • 92. Description of common primitive data types 92 Data Type Used For Memory(Turbo C compiler) int Integer data 2 bytes char Character data 1 byte float Real numbers data with single precision floating point 4 bytes double Real numbers data with double precision floating point 8 bytes long Long integer data 4 bytes unsigned Positive integer data 2 bytes
  • 93. First C Program 93 Following rules that are applicable to all C programs: • Each instruction in a C program is written as a separate statement. Therefore a complete C program would comprise of a series of statements. • The statements in a program must appear in the same order in which we wish them to be executed; unless of course the logic of the problem demands a deliberate ‘jump’ or transfer of control to a statement, which is out of sequence. • Blank spaces may be inserted between two words to improve the readability of the statement. However, no blank spaces are allowed within a variable, constant or keyword. • All statements should be entered in small case letters. • C has no specific rules for the position at which a statement is to be written. That’s why it is often called a free-form language. • Every C statement must end with a ;. Thus ; acts as a statement terminator.
  • 94. Printing Hello World on Screen 94 /* Printing Hello World*/ #include<stdio.h> void main( ) { printf(“hello world”); } Comment Preprocessor directive which is required to call printf function This is main function definition. Program execution starts from here. Call of printf function to display “hello world” on screen
  • 95. Compilation and Execution 95 • Once you have written the program you need to type it and instruct the machine to execute it. To type your C program you need another program called Editor. • There are several such IDEs available in the market targeted towards different operating systems. For example, Turbo C, Turbo C++ and Microsoft C are some of the popular compilers that work under MS-DOS; Visual C++ and Borland C++ are the compilers that work under Windows, whereas gcc compiler works under Linux.
  • 96. Compilation and Execution 96 Assuming that you are using a Turbo C or Turbo C++ compiler. Here are the steps that you need to follow to compile and execute your first C program. • Start the compiler at C> prompt. The compiler (TC.EXE is • usually present in C:TCBIN directory). • Select New from the File menu. • Type the program. • Save the program using F2 under a proper name (say • Program1.c). • Use Ctrl + F9 to compile and execute the program. • Use Alt + F5 to view the output.
  • 97. REFERENCES 97 • Sinha, P. K., & Sinha, P. BPB Publication. Computer Fundamental, Third Edition-2005, 12. • Kanetkar, Y. P. (2016). Let us C. BPB publications. • Overview of programming and problem solving by mcmillan computer science series. http://computerscience.jbpub.com/vbnet/pdfs/mcmilla n01.pdf