PPS NOTES with Video Lecture
PROGRAMMING FOR PROBLEM SOLVING
Unit 1 PDF
Digital Computer Output Unit
o Primary func ons of the output unit are to send the
A digital computer is machine that stores data in a numerical
processed results to the user .
format and performs opera ons on that using mathema cal
o Output devices display informa on in a way that the
manipula ons .
user can understand .
o It converts these coded results to human acceptable .
Processor
o Processor tells everything from your GPU to your disk
drivers and screen what to do.
o Example – intel , AMD
Main Memory
o Main memory stores data and programs .
o Main memory is also known as Primary memory.
I/O Modules
o It manages the communica on between a CPU and
network including transfer of data , management of
power , loads and control of machine func ons.
System Bus
o It provides the communica on among processor ,
CPU main memory , and I/O modules .
o It is a brain of computer . Motherboard
o CPU is a primary component of a computer that acts as o Motherboard serves as a single pla orm to connect all
its control center . parts of a computer together .
Memory unit o It connects CPU , memory , HDD etc.
o It can be referred as the storage area in which programs
are kept which are running that contains needed by
running programs .
o Memory unit generally categorize into two parts Memory hierarchy is organiza on of memory .It arranged according
o Primary memory Secondary memory to access me and capacity .
Primary Memory
o Primary memory is the fast in execute the program.
o It is vola le in nature , because when computer is
shutdown , then all data stored in primary memory is
lost .
o Example – RAM ,ROM
Secondary Memory
o Secondary memory is used when a large amount of data
and programs must be stored for a long-term basis.
o It is non-vola le in nature .
o Example – Magne c disks, pen drive , SSD
ALU Registers
o ALU operates the mathema cal calcula ons and logical o Register are special memory units which are used to
expressions. handle informa on between various units of computer
o Opera on such as mul plica on ,addi on, and speed up the rate of informa on transfer .
substruc on ,division , OR, AND , NOT etc.
Cache
Control Unit o It is smaller and faster memory that stores of couple of
o It is used to genera ng electric signals for various the data from frequently used main memory loca ons .
opera ons .
Main memory
o It manages and controls all the opera ons of the
o It is also known as RAM .
computer .
o It is vola le and when power is lost , informa on is lost
Input Unit too.
o Input unit are used by computer to read the data , most
Secondary memory
used input services are keywords , mouse , joys cks etc.
o It is non-vola le and used to store large amount of data.
o It is also called auxiliary memory .
Processor Func ons of OS
o Memory management
Processor is and integrated electronic circuit that perform o File management
calcula ons that run a computer. o Process management
A processor performs arithme c, logical, I/O, and other basic o Device management
instruc ons.
Assembler
Processor is also called CPU. But technically not correct since
It converts assembly language to machine code and called a
CPU is just one processor inside a personal Computer.
translator . Assemblers are like compiler .
GPU is another processor and even some hard drives technically
It takes basic command and opera ons from assembly code
capable of performing some processing.
and converts them into binary code .
Capabili es of processors are -: -
It produces executable object code. It is a system s/w.
o Ability to process instruc ons at a given me
Assembly language is a low-level language . and it is machine
o Max. number of instruc ons
dependent.
o Rela ve clock speed
Opera ons performed by processors -: - Compiler
o Fetch retrieves instruc on from a RAM. It translates a high-level language to machine language .
o Decode converts instruc on to signals. High-level languages are JAVA, C , C++ , Python
o Execute decoded instruc on are send to each Compiler scans all code of program and find errors and bugs ,
component so that desired opera ons can be and shows on the display , when no error and bugs find in file
performed. the compiler makes the object code of the program file .
At compila on me , program will not terminate when any
RAM[Random Access Memory]
error in program .
Ram is temporary memory bank, where your computer stores
A er the compila on , when you run the object code file the , it
data it need to retrieve quickly .
will give the output .
It is vola le memory.
Interpreter
ROM [Read Only Memory]
Interpreter is a program which translates High level language to
Rom is a non-vola le memory in nature.
machine code.
When you have to store large amount of data , then you can use
It runs the program line by line when any line through the error,
it .
then program will terminate .=
OS [opera ng System ] It does not make the object code.
OS is an interface between user and hardware. It is slower than compiler.
It operates all basic tasks like file managements memory
Linker
management , process management ,handle I/O modules .
It is a program in a system which helps to link object modules of
OS is a s/w that enables applica ons to interact with computer
a program into a single object file.
h/w .
It performs process of linking . and also called link editors
Linker is a program that links separately compiled modules into
one program.
It also combines func ons in standard C library with code that
we wrote.
Output of linker is an executable program . it is easy to
develop , test ,debug smaller program.
Loader
Loader is program that loads machine codes of a program into
system memory.
Executable file with extension exe is created , a er linking the
executable object code.
Output of the loader is an object program .
It is difficult to test and debug longer program.
Algorithm
An algo. Is a set of instruc ons for solving a problems or tasks.
Objec ves of OS
It can be finite step by step procedure to achieve a required
o Convenience result.
OS makes computer more convenient to use . Example -: - preparing a dish /Meal
o Efficiency Step of write an algorithm
OS allows the computer system resources to be used in Obtain a descrip on of a problem.
an efficient manner. Analyze the problem
o Ability to evolve Develop high level algorithm
OS should be constructed in such a way as to permit Refine algorithm by adding more details
effec ve development , tes ng . Review the algo
Proper es/characteris cs of Algorithm Step 1– Start the program.
Input & output must be specified. Step 2– Read/input the number.
Finiteness Step 3– Check if the number is even or odd.
Definiteness Step 4– display the output.
Effec veness Q. Flowchart and algo. To find a factorial of given number.
Flowchart
It is a pictorial form of process.
Every step indicated by shape. These shapes are connected by
lines/arrow to show the direc on of process.
Symbols of flowchart
step 1. Start
step 2. Read the number n
step 3. i=1, fact=1 step 4. Repeat
step 4 through 6 un l i=n
step 5. fact=fact*i
Advantages of Flowchart step 6. i=i+1
Clearly shows how control structure operates. step 7. Print fact
‘START’ and ‘STOP ‘ symbols are clearly indicated. step 8. Stop
Easy to understand Q. Flowchart and algo. To find greatest no. among three number.
Disadvantages of flowchart
Logic complexity
Difficult to show looping
Time consuming
Pseudocode
It is an informal language that helps programmers develop
algorithm .
It is straigh orward and text-biased design tool.
Example -: -
java code -> if (i<10){ i++; }
Pseudocode -> if i is less than 10 ,
Increment i by 1
Advantages of Pseudocode
Easily modified
Pseudocode easily converts into programming language.
Disadvantages of Pseudocode
Not visual
Communica on problem occurs due to lack of standardiza on.
Q. Flowchart and algo. to check given number is odd or even .
STEP
1:- START
STEP 2:- Declare three variables X,Y,Z.
STEP 3:-If X>Y&X>Z print X is the GREATEST.
STEP 4:-Otherwise if Y>Z&Y>X print Y is the GREATEST.
STEP 5:- Otherwise print Z is GREATEST.
STEP 6:- STOP
Basic structure of C program Keywords
Keywords are those words which specific meaning in C language.
#include<stdio.h> //preprocessor Directive
Keywords should not be used as variable names to avoid
int sum(int,int); //function prototype of sum() problems or compile me errors.
We have 32 keywords in C language ,which are these -: -
int a,b,c; //global variables
float d; //global variables
void main(){ //main function with return type
int x,y; //local variables
int z; //local variables
char ch ; //local variables
z=sum(x,y); //function call
int sum(int x1, int y1){ //function define sum()
return x1+y1; //return value of function sum
Standard I/O func on in C
C language provides set of built-in input and outputs func ons
Execu on of C Program to read and write opera ons .
Scanf func on reads the input from standard input stream or
Crea ng the program
user input.
Compiling the program
Prin func on writes the output to standard output stdout and
Linking program with func ons that are needed from the c
produces the output to the user.
library
Execu ng the program
Components of C language
Character set
Syntax Errors
o Ex ->Le ers, digits, special symbols , whitespaces
syntax errors occur when a programmer does not follow the set
Data type
of rules defined for the syntax of C language.
o Ex -> Int ,float , char ,double etc
Syntax errors are some mes also called compila on errors .
Constants
because they are always detected by the compiler.
o Ex> 2 , 4 ,5
For example, if you leave off a closing brace ( } ) when defining a
Variables
C func on, then trigger a syntax error.
o Ex-> Age , salary, name ,value
Logical Errors Keywords
A logic error is a 'bug' or mistake in a program's source code that o Ex ->For , do , if , con nue
results in incorrect or unexpected behaviour. Datatypes In C
if our expecta on is one thing and result output is other thing
C datatype are defined as the data storage format that a variable
then that kind of error we said it as “Logical errors”.
can store a data to perform a specific opera on.
These error are called run me errors .
Datatype is used to define a variable before to use in a program .
Object code Integer Data Type can store zero, posi ve, and nega ve values
Object code is the output of a compiler a er it processes the without any decimal.it is 4bytes.
source code. char datatype to store characters and le ers. However, the char
The object code is usually a machine code, also called a machine type is integer type because underneath C stores integer
language. numbers instead of characters.it is 1 byte.
Object code generally refers to the output of a compiled file. float data type is used to store floa ng-point values. Float in C
Executable code is used to store decimal and exponen al values.it is 8 bytes.
Executable code is the output of a linker a er it processes the long data type is also used to store big integer values. it is 8
object code. bytes.
Executable code is also called executable file or executable void type is usually used to specify the type of func ons returns
program. nothing .
ASCII Values Double is more precise than float and can store 64 bits, double
It stands for American Standard Code for Informa on of the number of bits float can store.it is 8 bytes.
Interchange. Variables in C
ASCII value is used to represent the character variables in A variable is a container . which store the data such as
numbers. integer,float,character,string etc.
ASCII value of "a" is 97 and “z” is 122 and “A” is 65 “Z” is 90 and Name of variable can be composed of le ers,digits and
“0” is 48 and “9” is 57 . underscore character.
It must begin with either le er or an underscore .
Upper and lower case le ers are dis nct.it means c language is
case sensi ve.
Scope of variable
It has three type 1. Local 2. Global 3. Sta c void main()
Local variable is local to block in which variable is defined. {
Global variable is global , i.e. if variable declared outside of the int i;
local func on , then variable is available to all func on that want for (i = 0; i < 3; i++)
to use it. {
Sta c Variable is local to block in which the variable is define ,it
sum();
remains allocated in the memory throughout the life of the
}
program irrespec ve of whatever func on.
}
Storage classes in C
C Storage Classes are used to describe the features of a
Output:
variable/func on. These features basically include the scope,
visibility, and life me. 10 24
There are 4 types of storage classes . 11 25
1.Automa c(auto) 2. External(extern) 12 26
3. Sta c(sta c) 4. Register(register)
Example of register storage class
#include <stdio.h>
int main()
{
register int a;
printf("%d",a);
}
Output:
garbage
Example of external storage class
#include <stdio.h>
Example of Automa c storage class int a;
#include <stdio.h> int main()
int main() {
{ extern int a;
int a , i;
printf("%d", a);
printf("%d ", a);
}
int a = 20; Output: 0
for (i = 0; i < 3; i++)
{
printf("%d ", a);
}
a=5;
printf("%d ", a);
}
Output:
Garbage 20 20 20 5
Example of sta c storage class
#include <stdio.h>
void sum()
{
static int a = 10;
static int b = 24;
printf("%d %d \n", a, b);
a++;
b++;
}