[go: up one dir, main page]

0% found this document useful (0 votes)
22 views44 pages

PPS unit-1

Uploaded by

patelridham2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views44 pages

PPS unit-1

Uploaded by

patelridham2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

DEPARTMENT OF INFORMATION TECHNOLOGY

Class:- B.E. 1st Year, Semester 2nd

Subject: Programming for Problem Solving


Subject code: 3110003
Semester : 2nd

Faculty Name : Mr. Ritesh Chauhan


Assistant Professor
Computer Science & Engg. Department
SNPIT&RC, Umrakh
Subject Overview
Sr. no. Units % Weightage
1 Introduction to computer and programming 11 %
2 Fundamentals of C 9%
3 Control structure in C 11 %
4 Array & String 13 %
5 Functions 11 %
6 Recursion 9%
7 Pointers 9%
8 Structure 9%
9 Dynamic memory allocation 9%
10 File management 9%

Reference books:
1. Programming in ANSI C by Balagurusamy
2. C Programming: Test Your Skills, 1/e by Ashok Kamthane
3. Programming With Ansi And Turbo C book : Ashok Kamthane ...
4. Programming in C Ansi standard, by Yashwant Kanetkar
UNIT-1
Introduction to Computer and Programming
❑ Topics to be covered
❖ Introduction
❖ Basic block diagram and functions of various components of computer
❖ Concepts of Hardware and software
❖ Types of software
❖ Compiler and interpreter
❖ Various types of Computer Languages
❖ Flowcharts and Algorithm
❖ Difference between Flowchart and Algorithm
Introduction
❑ What is Computer ?
✓ A Computer is a machine that accepts data as input, processes that data using
programs, and outputs the processed data as information. Many computers can
store and retrieve information using hard drives. Computers can be connected
together to form networks, allowing connected computers to communicate
with each other.
Computer History
✓ English Mathematician, Philosopher and
inventor
✓ 1791-1871
✓ Taught math at Cambridge University
✓ Invented a viable mechanical computer
equivalent to modern digital computer

Charles Babbage
BASIC BLOCK DIAGRAM OF COMPUTER
(IMP FOR EXAM)
❑ BASIC BLOCK DIAGRAM OF COMPUTER
❖ FUNCTIONS OF VARIOUS COMPONENT OF COMPUTER

✓ Computer is made up of mainly four components:

1. Central processing unit (CPU)

2. Input section

3. Output section

4. Storage Devices
1. Central processing unit (CPU)
✓ Central processing unit is a main part of the computer system.
• It contains electronics circuitry that processes the data based on instructions.
• It also controls the flow of data in the system.
• It is also known as brain of the computer.

✓ CPU consists of:-


i. Arithmetic Logic Unit (ALU):-
✓ It performs all arithmetic calculations and takes logical decision.
✓ It can perform add, subtract, multiply, compare, count, shift and other logical activities.
✓ It calculates very fast.
✓ It takes data from memory unit and returns data to memory unit, generally primary memory.
ii. Control Unit (CU):-
✓ It controls all other units in the computer system.
✓ It manages all operations
✓ It reads instruction and data from memory.
iii. Primary Memory:-
✓ It is also known as main memory.
✓ The processor or the CPU directly stores and retrieves information from it.
✓ Generally currently executing programs and data are stored in primary memory
✓ Its storage capacity is very small compared to secondary storage.
✓ It is very fast in an operation compared to secondary storage
✓ RAM is Random Access Memory and it is volatile in nature.
✓ ROM is Read Only Memory and it can hold data permanently.
▪ Types of ROM:
✓ PROM is Programmable Read Only Memory and it can hold data permanently.
Programmer can store information only once. Modification is not allowed.
✓ EPROM is Erasable Programmable Read Only Memory. It can hold data permanently.
Programmer can delete and write on it again and again.
2. Input section
✓ The devices used to enter data in to computer system are called input devices.
✓ It converts human understandable input to computer controllable data.
✓ CPU accepts information from user through input devices.
✓ Examples: Mouse, Keyboard, Touch screen, Joystick etc…

3. Output section
✓ The devices used to send the information to the outside world from the computer is
called output devices.
✓ It converts data stored in 1s and 0s in computer to human understandable information.
✓ Examples: Monitor, Printer, Plotter, Speakers etc..
4. Storage Devices (Secondary Memory)
✓ Secondary memory is also called Auxiliary memory or External memory.
✓ User can store data permanently.
✓ It can be modified easily.
✓ It can store large data compared to primary memory. Now days, it is available in
Terabytes.
✓ Examples: Hard disk, Floppy disk, CD, DVD, Pen drive, etc…
❑ ADVANTAGES AND LIMITATIONS OF COMPUTER
❖ Advantages:
✓ Speed: It can calculate millions of expressions within a fraction of second. The micro second and nano second
units are used to measure the speed of computers.

✓ Storage: It can store data in large quantity using various storage devices. Millions of paper file’s data can be
stored in single small pen drive. Moreover, it reproduces data whenever we need and whatever format we
need. Now a days, Gigabytes and Terabytes are units of data storage devises.

✓ Accuracy: Computer performs the computations at very high speed without any mistakes. For
example, multiplication of two very large number takes more time for human and there are high probabilities
of mistakes. Computer does it in parts of the second with accuracy level we want. Very high level of accuracy
is must in financial transaction, medical surgery, nuclear plant, etc… which can be satisfied by computer only.

✓ Reliability: It is very reliable device. The information stored in computer is available after years in same form.
It works 24 hours without any problem as it does not feel tiredness.

✓ Automation: Once the one task is created in a computer, it can be repeatedly performed again by single click
whenever we want. For example, once the software for banking application is installed in a computer, it
computes the interest by sending one command.
❑ ADVANTAGES AND LIMITATIONS OF COMPUTER
❖ Limitations:

✓ Lack of intelligence: It cannot think while doing work. It does not have natural intelligence.
It cannot think about properness or effect of work it is doing. It can only execute the
instructions but it cannot think about the correctness of these instructions.

✓ Unable to Correct Mistakes: It cannot correct the mistakes by itself. So if we have


provided wrong or incorrect data then it produces wrong results or performs wrong
calculations.
CONCEPTS OF HARDWARE AND SOFTWARE
❑ Software
✓ A set of instruction to perform a meaningful task is called program and a set
of program is called software. There are two types of software:

Types Of Software

System Software Application software


1. System Software
✓ System software is designed to operate the computer hardware efficiently. It provides and maintains a
platform for running application software.

✓ System software can be classified into three categories:


i. Operating system: It controls hardware as well as interacts with users, and provides different
services to user. It is a bridge between computer hardware and user. Ex: Windows 7, Linux, UNIX,
etc…

ii. System support software: It makes working of hardware more efficiently. For example drivers of
the I/O devices or routine for socket programming, etc…

iii. System development software: It provides programming development


environment to programmers. Example: Editor, pre-processor, compiler,
interpreter, loader, etc…..
2. Application software
✓ Application software is designed to help the user to perform general tasks (word processing, web browser …)
or some specific task (accounting, ticket booking …).
▪ Example: Enterprise software, Accounting software, Office suites, Graphics software and media players.

✓ Application software is classified into two categories:


i. General purpose software: It is used widely by many people for some common task, like word
processing, web browser, excel, etc… It is designed on vast concept so many people can use it.

ii. Special purpose software: It is used by limited people for some specific task like accounting software,
tax calculation software, ticket booking software, banking software etc… It is designed as per user’s
special requirement
❑ Hardware
✓ Physical parts of computer is known as Hardware. User can see and touch the hardware
components.

.
❑ Difference between Software and Hardware
COMPILER AND INTERPRETER
❑ Compiler

✓It translates programs of higher level language to machine language.


✓It converts whole program at a time.

void main() 0000 1100 0010


{ 0100
Source
int a=1,b=2,c; Compiler 0111 1000 0001
Target
c=a+b; Program 1111 0101 1110
Program
printf(“%d”,c); 1100 0000 1000
} 1011

Source Error Target


Program Messages (If any) Program

Fig: Compiler
❑ Interpreter

✓It translates programs of higher level language to machine language.


✓It converts program line by line.

Void main() 0000 1100 0010


{ 0000
int a=1,b=2,c; Interpreter 1111 1100 0010
c=a+b;
1010 1100 0010
printf(“%d”,c);
0011 1100 0010
} 1111
Error
Source Program Messages (If any) Target Program

Fig: Interpreter
❑ Difference Between compiler and interpreter

No. Compiler Interpreter

1 Compiler takes entire program as an input. Interpreter takes single instruction as an input.

2 Compiler does not allow program to run until it Interpreter runs the program from first line and
is completely error free stops execution only if it finds an error

3 Memory requirement is more. Memory requirement is less.

4 Error is displayed after entire program is Error is displayed for every instruction interpreted.
checked.

5 Example: C compiler Example: BASIC , Java interpreter


VARIOUS TYPES OF COMPUTER LANGUAGES
❑ VARIOUS TYPES OF COMPUTER LANGUAGES
✓ Computer languages may be classified in three categories:
1) Machine level language or Low level language.
2) Assembly language.
3) Higher level language.
1. MACHINE LEVEL LANGUAGE OR LOW LEVEL LANGUAGE
✓ Computer directly understands this language. It is a language of 0’s and 1’s
(binary).
❖ ADVANTAGES:
1. It is very fast in execution
2. It does not require any extra system or software to run the program.
3. Translation is not required.

❖ DISADVANTAGES:
1. Programs are long and difficult to write and understand for human.
2. Debugging is very difficult task.
3. It is not portable.
4. Programmer requires detailed knowledge of architecture of microprocessor.
2. ASSEMBLY LANGUAGE
✓ Every machine language instruction is assigned to English word MNEMONIC such that it should describe
function of instruction
✓ System cannot understand this language directly so we require translator that convert assembly language to
machine language. This translator is called assembler
✓ Example : 8086 Instruction Set
❖ ADVANTAGES:
1. Programs are easy to understand compared to machine level language.
2. Programs are smaller in size compared to machine level language.
3. Programs can be entered quickly using alphanumeric keyboard
❖ DISADVANTAGES:
1. It is not portable.
2. Programmer should know structure of assembly language of microprocessor.
3. It requires assembler as a translator
3. HIGHER LEVEL LANGUAGE
✓ We can write programs in English like manner and it is more convenient to use.
✓ Programmer can perform complex task by using high level languages with less efforts.
✓ It is similar to natural language and mathematical notation.
✓ Example: C, C++, Java, etc
❖ ADVANTAGES:
1. Easier to learn.
2. Requires less time to write.
3. Provides better documentation.
4. Easier to maintain.
5. It is portable.

❖ DISADVANTAGES:
1. It requires compiler or interpreter to convert higher level language to machine language.
2. Programmers need to learn structure of high level language.
3. It is bit slow compared to low level and medium level language.
FLOWCHARTS AND ALGORITHM
❑ FLOWCHARTS
✓ Flowchart is a pictorial or graphical representation of a process. Each step in the process is represented by a
different symbol and contains a short description of the process step. The flow chart symbols are linked
together with arrows showing the process flow direction. This pictorial representation can give step-by-step
solution of the given problem.
❖ ADVANTAGES:
1. Easy to draw.
2. Easy to understand logic.
3. Easy to identify mistakes by non computer person.
4. Easy to show branching and looping.

❖ DISADVANTAGES:
1. Time consuming.
2. Difficult to modify.
3. Very difficult to draw flowchart for big or complex problems.
❖ VARIOUS SYMBOL USED IN FLOWCHART
FLOW CHART SYMBOL MEANING EXPLANATION
This symbol denoting the beginning/start and
Start and end end of flow chart
This symbol is used to read input data and
Action / (input/output) output or display the information
This symbol is used to represent process. For
Step / Process example: Arithmetic operations, Data
movement etc..
Diamond symbol are generally used to check
Decision any condition or take decision for which there
are two answers: yes(true), no(false)
Flow lines are used to connect symbol used in
Flow lines / Arrow flow chart and indicate direction of flow

This symbol is used to connect or join


Connector
flow lines
❖ FLOW CHART EXAMPLE
❖ EXAMPLE: FLOW CHART TO FIND WHETHER THE GIVEN NUMBER IS EVEN OR ODD
❑ ALGORITHM
✓ Algorithm is step by step logical procedure to solve a given problem.
✓ It is written in the natural languages like English.

❖ ADVANTAGES:
1. Easy to write.
2. Human readable techniques to understand logic.
3. Algorithms for big problems can be written with less efforts.

❖ DISADVANTAGES:
1. Difficult to debug.
2. Difficult to show branching and looping.
3. Jumping (goto) makes it hard to trace some problems.
❖ EXAMPLE: ALGORITHM TO FIND WHETHER THE GIVEN NUMBER IS EVEN OR ODD

✓ Algorithm:
Step 1 : Start
Step 2 : Input no.
Step 3 : If no mod 2=0, goto 5.
Step 4 : Print given no is odd, goto 6.
Step 5 : Print given no is even.
Step 6 : Stop.
❑ DIFFERENCE BETWEEN FLOWCHART AND ALGORITHM

No. Flowchart Algorithm

1 It is a pictorial representation of a process. It is step wise analysis of the work to be done.

Solution is shown in non computer language


2 Solution is shown in graphical format.
like English.
Easy to understand as compared to
3 It is somewhat difficult to understand.
algorithm.

4 Easy to show branching and looping. Difficult to show branching and looping.

5 Flowchart for big problem is impractical Algorithm can be written for any problem
❖ EXAMPLE: ALGORITHM & FLOWCHART TO FIND THE SUM OF TWO NUMBERS

FLOW CHART
ALGORITHM:
Step-1 Start
Step-2 Input first numbers say A
Step-3 Input second number say B
Step-4 SUM = A + B
Step-5 Display SUM
Step-6 Stop
❖ EXAMPLE: ALGORITHM & FLOWCHART TO FIND THE SUM OF TWO NUMBERS

FLOW CHART
ALGORITHM:
Step-1 Start
Step-2 Input two numbers say A & B
Step-3 SUM = A + B
Step-4 Display SUM
Step-5 Stop
❖ EXAMPLE: ALGORITHM & FLOWCHART TO FIND SIMPLE INTEREST

P : Principle Amount
N : Time in Years FLOW CHART
R : % Annual Rate of Interest
SI : Simple Interest

ALGORITHM:
Step-1 Start
Step-2 Input value of P, N, R
Step-3 SI = (P x N x R)/100
Step-4 Display SI
Step-6 Stop
❖ EXAMPLE: ALGORITHM & FLOWCHART TO FIND THE LARGEST OF TWO NUMBERS

ALGORITHM:
FLOW CHART
Step-1 Start
Step-2 Input two numbers say NUM1,NUM2
Step-3 if NUM1 > NUM2 goto Step-5
Step-4 Print NUM2 is Largest goto Step-6
Step-5 Print NUM1 is Largest number
Step-6 Stop
❖ EXAMPLE: ALGORITHM & FLOWCHART TO FIND THE LARGEST OF TWO NUMBERS

ALGORITHM:
FLOW CHART
Step-1 Start
Step-2 Input two numbers say NUM1,NUM2
Step-3 if NUM1 > NUM2 goto Step-5
Step-4 Print NUM2 is Largest goto Step-6
Step-5 Print NUM1 is Largest number
Step-6 Stop
THANK YOU

You might also like