0% found this document useful (0 votes)
15 views

Chapter 1 - Basics of Programming

This document provides an overview of key concepts in programming, including: - It defines programming as providing instructions to a computer using a programming language to solve problems and perform tasks. - Key concepts covered include algorithms, programming languages, code, compilers, interpreters, debugging, and the software development life cycle. - Computer hardware and software are discussed, with hardware being the physical components and software being programs and instructions. - Hardware is classified into components like input/output devices, the CPU, memory, storage, motherboards, and more. - The chapter gives a foundation for understanding programming and computer systems at a high level.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Chapter 1 - Basics of Programming

This document provides an overview of key concepts in programming, including: - It defines programming as providing instructions to a computer using a programming language to solve problems and perform tasks. - Key concepts covered include algorithms, programming languages, code, compilers, interpreters, debugging, and the software development life cycle. - Computer hardware and software are discussed, with hardware being the physical components and software being programs and instructions. - Hardware is classified into components like input/output devices, the CPU, memory, storage, motherboards, and more. - The chapter gives a foundation for understanding programming and computer systems at a high level.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

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.

Introduction to Programming Concepts:


Programming is the process of instructing a computer to perform specific
tasks or operations by providing it with a set of instructions in the form of a program.
These instructions are written using a programming language, and they enable the

2|Page Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

computer to solve problems, manipulate data, and execute various functions.


Programming is a fundamental skill in computer science and software development, and
it encompasses several essential concepts and principles. In this introduction to
programming concepts, we'll explore some of the key ideas that underpin the world of
programming:

Algorithm: An algorithm is a step-by-step procedure or set of instructions designed to


solve a specific problem or perform a particular task. Algorithms are the building blocks
of programs, and they provide a logical and structured way to approach problem-solving.

Programming Language: A programming language is a formal system of rules and syntax


used to write code that can be executed by a computer. Examples of programming
languages include Python, Java, C++, and JavaScript. Each language has its own syntax and
capabilities.

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.

These fundamental programming concepts provide a solid foundation for


anyone interested in becoming a programmer or software developer.

Computer System is divided into two parts::

[A] Hardware
[B] Software

3|Page Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

Hardware, Classification of Hardware


Hardware refers to the physical components of a computer system that you
can touch, see, and interact with. It encompasses all the tangible parts of a computing
device that work together to process and store data. Hardware can be categorized into
several classes or classifications based on its functionality and role within a computer
system. Here are some common classifications of hardware:

[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.

Software, Classification of Software


Software refers to a collection of programs, data, and instructions that tell a
computer how to perform specific tasks or functions. It is a crucial component of modern
computing and can be categorized into various types based on its functionality and
purpose. Here, we'll explore the classification of software:

1. System Software:

[A] Operating Systems (OS): OS software manages computer hardware and


provides services for running applications. Examples include Windows, macOS,
Linux, and Android.
[B] Device Drivers: These software components enable communication between
the operating system and hardware devices like printers, graphics cards, and
network adapters.
[C] Utilities: Utilities are tools that perform system maintenance and management
tasks, such as disk cleanup, antivirus software, and system monitoring tools.
2. Application Software:

5|Page Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

[A] General-Purpose Applications: These are software applications designed for a


wide range of tasks, such as word processors (Microsoft Word), spreadsheets
(Microsoft Excel), and web browsers (Google Chrome).
[B] Specialized Applications: Specialized software serves specific industries or
professions, like graphic design software (Adobe Photoshop), video editing
software (Adobe Premiere), and 3D modelling software (AutoCAD).
[C] Productivity Software: Productivity software includes tools for creating
presentations (Microsoft PowerPoint), managing emails (Microsoft Outlook),
and organizing tasks (Microsoft OneNote).
[D] Entertainment Software: Entertainment software encompasses video games,
multimedia players (VLC Media Player), and streaming platforms (Netflix).
[E] Educational Software: Educational software aids in learning and includes
educational games, interactive simulations, and e-learning platforms.
3. Programming 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:

Embedded software runs on embedded systems, such as microcontrollers and


firmware in devices like smartphones, IoT devices, and automotive systems.

5. System Middleware:

Middleware software acts as an intermediary layer between the operating system


and application software. It facilitates communication and data exchange between
different software components.

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.

7. Closed Source Software:

6|Page Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

Closed source software, also known as proprietary software, is developed by


companies, and its source code is not publicly available. Examples include Microsoft
Office and Adobe Photoshop.

8. Freeware and Shareware:

Freeware is free to use, while shareware typically offers a trial version with limited
features and requires payment for full functionality.

9. Freeware and Shareware:

Freeware is free to use, while shareware typically offers a trial version with limited
features and requires payment for full functionality.

10. Cloud-Based Software: -

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.

7|Page Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of 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:

Instructions can be written in the format understandable by computer or can be converted


by computer is called as computer 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.

Types of programming languages:

Low Level Languages

Middle Level Languages

High Level Languages

Low Level Languages:

These are the languages which are understandable by computer.

e.g. Machine language , Assembly Language

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.

e.g. IBM executable, UNIX executable etc.

Advantages of Machine Language


• No need to have translator
• Less instruction set.

Disadvantages of Machine Language:


• Very fast to execute
• Error prone
• Difficult to learn, & debug
• Machine Dependent programs

Applications of Machine Language:


• To write system programs.
• To convert HLL to machine understandable format.

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

Disadvantages of Assembly Language:


9|Page • needs a translator Notes By, Dr. Vijaya Waidande
• more instruction set
Chapter 1: Basics of Programming

Middle Level Languages


These are the languages which has power of low level languages and high level languages.
These languages are used for system programming, utility programming and application
programming also.

e.g. C, C++, Ada, Simula, Java, Pascal, Delphi etc.

Advantages of Middle Level Language


• Easy to learn & debug
• Machine Independent programs

Disadvantages of Middle Level Language:


• needs a translator
• more instruction set

Applications of Middle Level Language:


• To write both type of applications i.e. application
& utility soft wares

High Level Languages:


The languages which are not understandable by computer but are very easy for human
being to learn, understand and to use. These languages are used for application programming.
These languages are similar to English language.

e.g. BASIC, ALGOL, CPL, COBOL etc.

Advantages of High Level Language


• Very Easy to learn & modify.
10 | P a g e • Machine Independent programs Notes By, Dr. Vijaya Waidande
Chapter 1: Basics of Programming

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.

11 | P a g e Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

e.g. C,C++,JAVA etc has Compiler.

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.

LLL Program Dis - Compiler HLL Program

Dis - Assembler:
It converts machine language program into assembly language program.

Machine Language Program Dis - Compiler HLL Program

12 | P a g e Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

Difference between compiler & interpreter

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

If error is there, it converts till one line before


If any error is there, it doesn’t convert.
the error line and executes & then shows error.

It requires less time to convert but as for every


It requires conversion time, but execution time
statement it converts & then executes, it takes
is more.
more time for execution

A file is generated for target code e.g. prime.c


will generate prime.o or prime.out or It doesn’t generate a target file.
prime.obj.

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

It is finite sequence of instructions that is followed to accomplish or performs some task.

Daily Life Examples of an algorithm-

to make tea/coffee, to make a phone call etc.

Consider the procedure of making tea:

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.

Computerized Examples of an algorithm:


Features of computerized algorithms:

• Every algorithm has 2 common steps start and stop.


• To take input, use the words as Input or Accept or Read or Input.
• To display output, use the words as display or print or show.
• Convert mathematical formulas in expressions.
• Simple arithmetic operators that can be used are +,-,*,/ and % where / is used to get the
division part and % is used to get remainder when one number is divided by another.
e.g. if a=10 and b=2 then a/b is 5 and a%b is 0.

if a=11 and b=2 then a/b is 5 and a%b is 1.

Simple algorithms based on Expressions:


Ex.1) Algorithms to find addition of 2 numbers :

(Addition is given by + opeartor)

1) Start.
2) Accept 2 numbers a and b.
3) c=a+b.
4) print c.
5) stop.

Ex.2) Algorithms to find subtraction of 2 numbers :

(Subtraction is given by - opeartor)

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.

Ex.3) Algorithms to find multiplication of 2 numbers :

14 | P a g e Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

(Multiplication is given by * operator)

1) Start.
2) Accept 2 numbers a and b.
3) c=a*b.
4) print c.
5) stop.

Ex.4) Algorithms to find division of 2 numbers :

(Division is given by / operator)

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.

Ex.5) Algorithms to find remainder of 2 numbers :

(Remainder is given by % operator)

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.

Ex.6) Algorithms to find area of circle:

(Area of circle is given by the formula a= r2)

1) Start.
2) Accept r.
3) A=3.142*r*r.
4) Display Si.
5) Stop.

15 | P a g e Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

Ex.7) Algorithms to find perimeter of Circle:

(perimeter of circle is given by the formula p= 2r)

1. Start
2. Accept radius r
3. c=2*r
4. Print C
5. Stop.

Ex.8) Algorithm to convert temperature from Fahrenheit to Celsius:

(Fahrenheit to Celsius conversion formula is: C=5/9*(F-32) )

1. Start.
2. Accept temperature in F (Fahrenheit value).
3. C=5.0/9*(F-32).
4. Print C.
5. Stop.

Ex.9) Algorithm to calculate simple Interest:

(Simple Interest formula is: Simple Interest =pnr/100 )

1) Start.
2) Accept p,n,r.
3) A=p*n*r
4) Si=a/100.0;
5) Display Si
6) Stop.

Ex.10) Algorithm to swap (interchange) 2 numbers using third variable:

(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.

Ex.11) Algorithm to calculate swap (interchange) 2 numbers without

16 | P a g e Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

using third variable:

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.

Algorithms based on Decision making i.e. condition checking::


In this algorithms, simple if statement can be used to check a condition and take decision
according to condition. Use if…then…else statement to check the condition.

Ex.12) Maximum of 2 numbers :

(e.g. if a=10 and b=20 then maximum number is 20 i.e. b )

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.

Ex.13) Maximum of 3 numbers :

(e.g. if a=10 , b=20 and c=50 then maximum number is 30 i.e. c )

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.

Algorithms based on Repetitive statements:

17 | P a g e Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

In these algorithms, some statements have to be executed n number of times depending


on the condition and the problem statement. Use goto statement to repeat same statement.

Ex.13) Sum of first n natural numbers:

(e.g. if n is 5 then display 15 since 1+2+3+4+5 = 15 )

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.

Ex.14) Sum of first n user defined numbers:

( User defined numbers means user has to enter n numbers .

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.

Ex.15) Display first ‘n’ natural numbers :

(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.

18 | P a g e Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

Ex.16) Display first ‘n’ natural numbers in reverse order.

(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.

Ex.17) Compound Interest.

(Compound Interest formula is: compound interest=(p+n/100) r )

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 :

e.g.: if input => 34 then output => 81 since 34 = 3 * 3 * 3 * 3 = 81

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

Ex.19) a*b without using *.


19 | P a g e Notes By, Dr. Vijaya Waidande
Chapter 1: Basics of Programming

Logic: a + a + a + … + a b times.

e.g.: if input => 3*4 then output => 12 since 3*4=3+3+3+4=12

Logic: X+X+X…+X…. Y 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.

Ex.20) a/b without using / :

Logic: a-b-b-… till this subtraction is >=b and increment the counter
simultaneously.

e.g.: if input => 13/4 then output => 3

since 13-4=9 counter =1

9-4=5 counter =2

5-4=1 counter =3

1-4=-3 hence stop the procedure.

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.

Ex.21) a % b without using %:

Logic: a-b-b-… till this subtraction is >=b and display last subtraction.

e.g.: if input => 13%4 then output => 1

20 | P a g e Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

since 13-4=9 9>=4 Hence continue the procedure.

9-4=5 5>=4 Hence continue the procedure.

5-4=1 1>=4 Hence continue the procedure.

1-4=-3 -3<4 Hence stop.

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.

Ex.22) Fibonacci Series:

Ex.: if input is 7 then output is 0,1,1,2,3,5,8,…

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

Ex.23) GCD and LCM of 2 numbers:

GCD is Greatest Common Divisor and LCM is Least Common divisor.

If a=10 and b=25 then GCD=5 and LCM=50.

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

21 | P a g e Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

8) GCD=a
9) LCM= prod/a
10) Stop

Ex.24) Sum of digits:

If n=1234 then sum of digits = 1+2+3+4=10

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.

Ex.25) Count no. of digits:

If n=1234 then total number of digits = 4

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.

Ex.26) Check whether a number is odd or even.

If n=12 then number is even. If n=13 then number is odd.

Since remainder after dividing such numbers by 2 is either 0 or 1.

e.g. 12%2 = 0 and 13%2 = 1

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.

22 | P a g e Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

Ex.27) Check whether a number is prime or not

A number ( except 1 ) which is divisible by 1 and itself only.

e.g. 17 is the prime number since it is divisible by 1 and 17 only.

9 is not the prime number since it is divisible by 3.

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.

Ex.28) Check whether a number is perfect or not.

A number is said to be perfect addition of it’s proper divisors is the number itself.

If n=6 is the perfect number.

Since proper divisors of 6 are: 1,2 and 3.

Sum of these factors=1+2+3=6 ….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.

A number is said to be Armstrong if addition of cubes of it’s digits is the number


itself.

If n=153 is the Armstrong number.

Since digits of 153 are: 1,5 and 3.

Sum of these digits=13+53+33=1+125+27=153 ….number itself.


23 | P a g e Notes By, Dr. Vijaya Waidande
Chapter 1: Basics of Programming

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.

Ex.30) Check whether a number is square number or not.

A number is said to be square number if square root of such number is integer


number (number without fractional point part.).

If n=4 then it is the square number.

Since square root of 4 is 2.

If n=5 then it is not the square number.

Since square root of 5 is 2.2355 …. Not an integer

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.

Ex.31) Check whether a number is cube number or not.

A number is said to be cube number if cube root of such number is integer number
(number without fractional point part.).

24 | P a g e Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

If n=9 then it is the cube number.

Since cube root of 9 is 3.

If n=10 then it is not the cube number.

Since cube root of 10 is 3.333 …. Not an intege

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.

Notations used in flowchart:

Symbol name Used for Shape Example

to start & stop


instructions Start Stop
Oval

Parallelogram For input & output


Accept Display
a b

Rectangle Process
c=a+b

Diamond Decision making


True
a>b
?

False

25 | P a g e Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

Connector to connect 2 parts


of flow charts A
A
Flow lines to connect two
shapes of flow Accept
a
chart

c=a+b

26 | P a g e Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

Examples:

Ex.1)Addition of 2 numbers
Start

Accept a,b

c=a+b

Display c

Stop

Ex.2) Maximum of 3 numbers :

Start

Accept a,b,c

False True
a>b ? b>c ?

False
True
False
a>c ?

True

Display a Display c Display b

27 | P a g e Stop Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

Ex.3) Sum of n user defined numbers:


Start

Accept n

i=0 , sum =0

False

Is (i<n) ?

True

Accept b

i= i+1

Display sum

Stop

28 | P a g e Notes By, Dr. Vijaya Waidande


Chapter 1: Basics of Programming

Ex.3) Sum of n user defined numbers:

Start

Accept n

i=0 , sum =0

False
i<n ?

i= i+1 True STOP


sum=sum + b
Accept b

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:::

Q.1) Define the following

a) Machine Language b) Low level Language c) High Level Language


d) Translator e) Compiler f) Interpreter
g) Algorithm h)flowchart i)program

Q.2) Differentiate between

1. Compiler & interpreter


2. Machine Language & High-level languages
3. Low Level Languages & High-level languages
4. Application and system software
Q.3) Short Answer Questions:

[1] What is the primary purpose of programming?


[2] Define "programming language" in one sentence.
[3] Why is problem-solving important in programming?
[4] Give a one-sentence definition of an "algorithm."
[5] What does "debugging" mean in programming?
[6] In programming, what is the "output" of a program?
[7] Name one high-level programming language.
[8] What does a "compiler" do in programming?
[9] What is the role of a "function" in coding?
[10] Why is "problem decomposition" essential in programming?
[11] What is the definition of software in the context of computers?
[12] Name two categories of software and provide an example of each.
[13] Differentiate between system software and application software.
[14] Give an example of utility software and explain its purpose.
[15] What is open-source software, and how does it differ from proprietary software?
[16] Define modular programming in programming terminology.
[17] Why is modular programming considered good practice in software development?
[18] What is a "module" in the context of modular programming?
[19] How can modular programming improve code maintainability?
[20] Provide an example of breaking a program into modules.
[21] Explain the key principle of structured programming.
[22] What are control structures in structured programming?
[23] Name two commonly used control structures in programming.
[24] How does structured programming help in avoiding "spaghetti code"?
[25] Give an example of a structured programming code snippet.
30 | P a g e Notes By, Dr. Vijaya Waidande
Chapter 1: Basics of Programming

[26] What is an algorithm, and why is it essential in programming?


[27] Define a flowchart and explain its role in program design.
[28] Provide a simple algorithm for finding the sum of two numbers.
[29] Create a flowchart for a program that checks if a number is even or odd.
[30] Describe a real-life scenario and provide an algorithm for solving it (e.g., making a
sandwich).
[31] What is a computer programming language, and why is it essential in software
development?
[32] Explain the difference between high-level programming languages and low-level
programming languages.
[33] Name and briefly describe three high-level programming languages.
[34] What are the advantages of using high-level programming languages over low-level
languages?
[35] Define "assembly language" and explain its role in programming.
[36] Differentiate between compiled languages and interpreted languages. Provide
examples of each.

31 | P a g e Notes By, Dr. Vijaya Waidande

You might also like