Chapter 1 - Basics of Programming
Chapter 1 - Basics of Programming
Prepared by ,
Dr. Veejya Kummbhar,
Sr. Assistant Professor,
School of Computer Studies,
Sri Balaji University, Pune
Chapter 1: Basics of Programming
Syllabus ::
1.1 Introduction to Programming Concepts:
1.2 Software, Classification of Software
1.3 Modular Programming,
1.4 Structured Programming
1.5 Algorithms and Flowcharts with examples
----------------------------------------------------------------------------------------------------------------------------
Table of Contents
Basics of Programming ......................................................................................................................................... 1
Introduction to Programming Concepts:............................................................................................................. 2
Hardware, Classification of Hardware ................................................................................................................. 4
Software, Classification of Software..................................................................................................................... 5
Modular Programming.......................................................................................................................................... 7
Structured Programming ...................................................................................................................................... 7
Computer Languages ............................................................................................................................................ 8
Translator/Converter ................................................................................................................................. 11
Types of translators: ........................................................................................................................................... 11
Complier: .............................................................................................................................................................. 11
Interpreter: .......................................................................................................................................................... 12
Algorithms ........................................................................................................................................................... 13
Flow chart: ........................................................................................................................................................... 25
Questions::: .......................................................................................................................................................... 30
This chapter gives the idea about all required concepts to begin programming.
Code: Code refers to the written instructions in a programming language that make up a
program. Code is typically written by programmers to create software applications,
websites, or other computer programs.
Compiler and Interpreter: Compilers and interpreters are tools used to convert human-
readable code into machine-executable code. A compiler translates the entire program
into machine code before execution, while an interpreter translates and executes the code
line by line.
Debugging: Debugging is the process of identifying and fixing errors or bugs in a program.
Debugging tools and techniques help programmers locate and correct issues in their code.
Software Development Life Cycle (SDLC): SDLC is a systematic process for planning,
creating, testing, and maintaining software. It includes phases such as requirements
analysis, design, coding, testing, deployment, and maintenance.
[A] Hardware
[B] Software
[1] Input Devices: Input devices allow users to provide data and instructions to the
computer. Examples include keyboards, mice, touchscreens, scanners, and
microphones.
[2] Output Devices: Output devices display or provide the results of computer
processing to users. Common output devices include monitors, printers,
speakers, and projectors.
[3] Central Processing Unit (CPU): The CPU is the brain of the computer,
responsible for executing instructions and performing calculations. It interprets
and executes program instructions stored in memory.
[4] Memory (RAM): Random Access Memory (RAM) is a type of volatile memory
that temporarily stores data and program instructions that the CPU is currently
using. It allows for quick access to data but loses its contents when the computer
is powered off.
[5] Storage Devices: Storage devices are used to store data and programs for long-
term use. Examples include hard disk drives (HDDs), solid-state drives (SSDs),
optical drives (e.g., CD/DVD drives), and USB flash drives.
[6] Motherboard: The motherboard is the main circuit board of the computer,
connecting and providing power to all other hardware components. It houses
the CPU, RAM slots, and connectors for other components.
[7] Graphics Processing Unit (GPU): GPUs are specialized hardware components
designed to handle graphics and rendering tasks. They are commonly used for
gaming, video editing, and other graphics-intensive applications.
[8] Network Interface Card (NIC): NICs enable computers to connect to networks,
including local area networks (LANs) and the internet. They can be integrated
into the motherboard or added as expansion cards.
[9] Power Supply Unit (PSU): The PSU provides electrical power to all components
of the computer. It converts electricity from an external source (e.g., a wall
outlet) into the voltage levels required by the computer's components.
[10] Expansion Cards: These are optional hardware components that can be added
to a computer to provide additional functionality. Examples include sound cards,
network cards, and graphics cards.
[11] Cooling Systems: Cooling systems, including fans and heat sinks, are essential to
prevent computer components from overheating during operation.
4|Page Notes By, Dr. Vijaya Waidande
Chapter 1: Basics of Programming
[12] Peripherals: Peripherals are additional hardware devices that can be connected
to a computer to extend its functionality. Examples include external hard drives,
webcams, and external sound systems.
[13] Embedded Systems: These are specialized hardware components and
microcontrollers designed for specific tasks or applications. Examples include
the microcontrollers in household appliances, automobiles, and industrial
machinery.
[14] Servers and Data Centers: In enterprise environments, hardware is organized
into servers and data centers to support networked computing, storage, and data
processing.
[15] Mobile Devices: Hardware in mobile devices, such as smartphones and tablets,
includes touchscreen displays, batteries, processors, and sensors.
These classifications provide an overview of the diverse range of hardware
components that make up modern computer systems. The interaction and coordination of
these components enable computers to perform a wide variety of tasks and functions, from
basic calculations to complex data analysis and multimedia processing.
1. System Software:
[A] Text Editors: Text editors like Notepad++ and Visual Studio Code are used for
writing and editing source code.
[B] Integrated Development Environments (IDEs): IDEs, such as Eclipse, Visual
Studio, and PyCharm, offer a complete development environment with code
editors, debuggers, and build tools.
[C] Compilers and Interpreters: Compilers (e.g., GCC) translate source code into
machine code, while interpreters (e.g., Python) execute code line by line.
4. Embedded Software:
5. System Middleware:
6. Open-Source Software:
Open source software is developed collaboratively, and its source code is made
available to the public. Examples include the Linux operating system and the Mozilla
Firefox web browser.
Freeware is free to use, while shareware typically offers a trial version with limited
features and requires payment for full functionality.
Freeware is free to use, while shareware typically offers a trial version with limited
features and requires payment for full functionality.
Cloud-based software runs on remote servers and is accessed over the internet.
Examples include Google Workspace (formerly G Suite) and cloud storage services
like Dropbox.
These are the primary categories of software, each serving specific purposes and catering
to various user needs. The software industry continues to evolve with advancements in
technology, leading to the development of new types of software and innovative solutions.
Modular Programming
Modular programming, also known as modular design or modularization, is
a software development approach that divides a computer program into separate, self-
contained modules or components. Each module is responsible for a specific piece of
functionality within the program and can be developed, tested, and maintained
independently. The key principles and benefits of modular programming include:
Structured Programming
Structured programming is a programming paradigm that emphasizes the
use of structured control flow and modular design to create clear, understandable, and
maintainable code. It was developed in the late 1960s as a response to the perceived
shortcomings of earlier programming approaches, such as assembly language and ad-hoc
programming.
Computer Languages
This concept gives the background information of programming so as to understand a
computing environment in which to work as a programmer. Before starting the programming, it
is necessary to know some important terms in programming environment & the basics of
programming languages.
Program:
Language:
It is a way of communication between 2 human beings. It gives the means to convey the
message from one entity to another.
Computer Language:
It is a way of communication between human being and computer. It is actually used for
solving a problem or to give the instructions & then use it for further reference.
a) Machine Language:
8|Page Notes By, Dr. Vijaya Waidande
Chapter 1: Basics of Programming
Computer is an electronic machine which can understand the only language i.e. ON & OFF.
In computer we represent ON as ‘1’ & OFF as ‘0’. As there only 2 digits which are understandable
by computer, this digits are called as binary digit or bit .A program can be written using binary
language is understandable by computer as such program which consists of 0’s and 1’s is directly
converted into electrical signals. This language is known as machine language.
b) Assembly Language:
Every time to write the programs in machine language, was very difficult, error prone and
time consuming job for the programmers of early days of computers. Hence a program was
written which can take simple language statements than machine language and converts into
machine code. This new language is assembly language and converter is known as assembler.
As after machine language, it is only the language which is close to computer, it is classified
in low level languages. These languages are used for system programming.
e.g. MASM ( Microsoft Assembler), TASM ( Turbo Assembler ) , NASM( Netwide Assembler
) Advantages of Assembly Language
• less error prone
Translator/Converter:
It is the program which converts source program into target program. Source program
can be in high level or in assembly language. Target program is in machine language.
Translator
Source program Target program
Types of translators:
Assembler:
It converts assembly language program into machine language.
e.g. MASM (Micosoft Assembler) ,TASM ( Turbo Assembler) ,NASM (Netwide Assembler).
Assembler
Assembly Program LLL Program
Complier:
It converts high level language into low level or machine language.
Compiler
HLL Program LLL Program
Interpreter:
It converts each & every statement into low level language & immediately executes it
without storing it.
e.g. BASIC language has interpreter, JAVA has interpreter, Python has interpreter.
One statement of HLL Program Interpreter Generate LLL code & show output
Next statement
Dis - Complier:
It converts low level language program into high level language program.
Dis - Assembler:
It converts machine language program into assembly language program.
Complier Interpreter
It converts high level language statements into
It converts into low level language but executes
low level & generates another file for object
immediately.
code
Algorithms
Before programming, it is necessary to know how to write procedure & then how to convert this
procedure into program. This procedure is nothing but an algorithm.
Algorithm - Definition
a) Take a vessel.
b) Add 1 cup of water.
c) Mix 1 spoon sugar and ½ cup of powder.
d) Put the vessel on gas
e) Boil the tea for 5 minutes.
13 | P a g e Notes By, Dr. Vijaya Waidande
Chapter 1: Basics of Programming
f) Mix 1 cup of milk in boiled tea and again boil for 2 minutes.
g) Sort it in cup and serve.
Here we can’t execute any step after anyone, Hence sequence is important.
1) Start.
2) Accept 2 numbers a and b.
3) c=a+b.
4) print c.
5) stop.
1) Start.
2) Accept 2 numbers a and b.
3) c=a-b.
4) print c.
5) c=b-a
6) print c.
7) stop.
1) Start.
2) Accept 2 numbers a and b.
3) c=a*b.
4) print c.
5) stop.
1) Start.
2) Accept 2 numbers a and b.
3) c=a/b.
4) print c.
5) c=b/a
6) print c.
7) stop.
1) Start.
2) Accept 2 numbers a and b.
3) c=a%b.
4) print c.
5) c=b%a
6) print c.
7) stop.
1) Start.
2) Accept r.
3) A=3.142*r*r.
4) Display Si.
5) Stop.
1. Start
2. Accept radius r
3. c=2*r
4. Print C
5. Stop.
1. Start.
2. Accept temperature in F (Fahrenheit value).
3. C=5.0/9*(F-32).
4. Print C.
5. Stop.
1) Start.
2) Accept p,n,r.
3) A=p*n*r
4) Si=a/100.0;
5) Display Si
6) Stop.
(e.g. if a=10 and b=20 then swap means A=20 and b=10 )
1) Start
2) Accept 2 numbers a,b
3) c=a
4) a=b
5) b=c
6) Display a, b
7) Stop.
1) Start
2) Accept 2 numbers a,b
3) a=a+b
4) b=a-b
5) a=a-b
6) Display a, b
7) Stop.
1) Start.
2) Accept 2 numbers a and b.
3) if a>b then print a.
4) if b>a then print b.
5) stop.
1) Start.
2) Accept 2 numbers a and b.
3) if a>b and a>c then print a.
4) if b>a and b>c then print b.
5) if c>a and c>b then print c.
6) stop.
1) Start.
2) Accept n.
3) i=1 , sum =0
4) if i==n goto step 7
5) sum = sum+i
6) i=i+1 goto step 4.
7) Display sum.
8) Stop.
e.g. if n is 5 then accept 5 numbers . e.g 5 numbers are 3 ,4,2,10 and 6 then display 25 since
3+4+2+10+6 = 25 )
1) Start.
2) Accept n.
3) i=1 , sum =0
4) if i==n goto step 8
5) Accept no .
6) sum = sum+no
7) i=i+1 goto step 4.
8) Display sum.
9) Stop.
(e.g. if n is 5 the display natural numbers series upto n i.e. upto 5 such as
1 2 3 4 5 )
1) Start.
2) Accept n.
3) i=1
4) if i==n goto step 7
5) Print i
6) i=i+1 goto step 4.
7) Stop.
(e.g. if n is 5 the display natural numbers series upto n i.e. upto 5 such as
5 4 3 2 1 )
1) Start.
2) Accept n.
3) i=n
4) if i==0 goto step 7
5) Print i
6) i=i-1 and goto step 4.
7) Stop.
1) Start
2) Accept p,n,r
3) a=p+n/100.0
4) ci=1, i=1
5) ci=ci*a
6) i=i+1
7) if i<=r goto Step 5
8) Display ci
9) Stop
Ex.18) XY :
Logic: X * X * X … * X …. Y times.
1) Start
2) Accept x,y
3) m=1, i=1
4) m=m*x
5) i=i+1
6) if i<=r goto Step 5
7) Display m
8) Stop
Logic: a + a + a + … + a b times.
1) Start
2) Accept a,b
3) Sum=0
4) i=0
5) If i==b goto Step 9
6) Sum=sum+a.
7) i=i+1.
8) Goto Step 5
9) Display sum
10)Stop.
Logic: a-b-b-… till this subtraction is >=b and increment the counter
simultaneously.
9-4=5 counter =2
5-4=1 counter =3
1) Start
2) Accept a,b
3) div=a
4) i=0
5) div=div-b
6) if div >=b then i=i+1 and goto Step 5
7) Display i
8) Stop.
Logic: a-b-b-… till this subtraction is >=b and display last subtraction.
1) Start
2) Accept a,b
3) div=a
4) div=div-b
5) if div >=b then and goto Step 4
6) Display div
7) Stop.
1) Start
2) Accept n.
3) a=0,b=1
4) Display a,b
5) i=2
6) c=a+b
7) If i==n goto Step 12
8) Display c
9) i=i+1
10)a=b
11)b=c goto Step 6
12)Stop
1) Start
2) Accept 2 numbers a and b
3) m=a , n=b
4) prod=m*n
5) if a>b then a=a-b
6) if a<b then b=b-a
7) if a!=b then go to Step 5
8) GCD=a
9) LCM= prod/a
10) Stop
1) Start
2) Accept n
3) m=n
4) Sum=0
5) Sum=sum+m%10
6) m=m/10
7) if m>0 then goto Step 5
8) Display sum
9) Stop.
1) Start
2) Accept n
3) m=n
4) i=0
5) if m==0 then goto Step 8
6) m=m/10
7) i=i+1
8) Display i
9) Stop.
1) Start.
2) Accept a number say x.
3) If x%2==0 then display it is EVEN.
4) Else display it is ODD.
5) Stop.
1) Start.
2) Accept a number say x.
3) i=2
4) If x%i==0 then got Step 7
5) i=i+1
6) if i<=n/2 then goto Step 4 Else got Step Step 8
7) Display Not Prime. Goto Step 9.
8) Display Prime.
9) Stop.
A number is said to be perfect addition of it’s proper divisors is the number itself.
1) Start.
2) Accept a number say x.
3) i=1, sum=0
4) If x%i==0 then sum=sum + i
5) i=i+1
6) if i<n then goto Step 4
7) if i==n then display PERFECT
Else Display Not PERFECT
8) Stop.
Ex.29) Check whether a number is Armstrong or not.
1) Start.
2) Accept a number say x.
3) i=1, sum=0, m=x
4) y=x%10
5) sum=sum + y*y*y
6) x=x/10
7) if x!=0 then goto Step 4
8) if m==sum then display ‘No is Armstrong’
Else Display ‘Not Armstrong’
9) Stop.
1) Start.
2) Accept a number say x.
3) i=1
4) if i*i=x then goto step 7.
5) if i*i>x then got0 step 8.
6) i=i+1 and goto step 4.
7) Display ‘Square Number’ and goto step 9.
8) Display ‘Not a Square Number’
9) Stop.
A number is said to be cube number if cube root of such number is integer number
(number without fractional point part.).
1) Start.
2) Accept a number say x.
3) i=1
4) if i*i*i=x then goto step 7.
5) if i*i*i>x then got0 step 8.
6) i=i+1 and goto step 4.
7) Display ‘Cube Number’ and goto step 9.
8) Display ‘Not a Cube Number’
9) Stop.
Flow chart:
It is pictorial representation of instructions’ pictorial representation of an algorithm.
It gives the idea about the logic of the program & the flow of instructions.
Rectangle Process
c=a+b
False
c=a+b
Examples:
Ex.1)Addition of 2 numbers
Start
Accept a,b
c=a+b
Display c
Stop
Start
Accept a,b,c
False True
a>b ? b>c ?
False
True
False
a>c ?
True
Accept n
i=0 , sum =0
False
Is (i<n) ?
True
Accept b
i= i+1
Display sum
Stop
Start
Accept n
i=0 , sum =0
False
i<n ?
True
i= i+1
sum=sum + b
Display sum
29 | P a g e Notes By, Dr. Vijaya Waidande
Chapter 1: Basics of Programming
Questions:::