0% found this document useful (0 votes)
2 views31 pages

Unit 1

The document outlines the process of problem solving with computers, detailing steps such as problem analysis, algorithm development, flowcharting, coding, compilation, debugging, testing, and documentation. It emphasizes the importance of planning and structuring programs before coding, providing examples of algorithms for various tasks. Additionally, it discusses flowchart advantages, limitations, and guidelines, as well as the basic structure of a C program.

Uploaded by

yamkumar077a
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)
2 views31 pages

Unit 1

The document outlines the process of problem solving with computers, detailing steps such as problem analysis, algorithm development, flowcharting, coding, compilation, debugging, testing, and documentation. It emphasizes the importance of planning and structuring programs before coding, providing examples of algorithms for various tasks. Additionally, it discusses flowchart advantages, limitations, and guidelines, as well as the basic structure of a C program.

Uploaded by

yamkumar077a
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/ 31

Unit 1.

Problem Solving with


Computer
Problem Analysis, Algorithms and Flowchart,
Coding, Compilation and Execution, History of C,
Structure of C program, Debugging, Testing and
Documentation

1
Problem Solving with Computer
 There are a no. of problems to be solved using computer e.g.
sometimes we have to calculate simple interest when
principal money, time and rate of interest is provided, and
sometimes we have to prepare mark sheet of a student and
calculate his percentage.
 How?????
 Write a program in computer.
 But a program must be planned before coding in a
programming language so as to make sure that
program/instructions are appropriate to solve the problem
and are in the correct sequence.

2
Problem Solving with Computer…
 There are a no. of steps while solving a problem using
computer. They are:
1) Problem Analysis
2) Algorithm Development
3) Flowcharting
4) Coding
5) Compilation & Execution
6) Debugging & Testing
7) Documentation

3
1) Problem Analysis
 This step is the process of becoming familiar (by analyzing and
understanding)with the problem that will be solved with a
computer program.
 The program’s inputs, outputs, different ways of solving problems,
its constraints, software and hardware requirements, available time
period should be known in advance.
 E.g. when we have to prepare banking solution, we must know
different activities to be done in a bank, required input forms and
output reports.
 This is the task of a system analyst.
 Note: Inadequate recognition of a problem may cause program
less useful and insufficient.

4
2) Algorithm Development
 An algorithm is a step-by-step description of the method to
solve a problem.
 Algorithm maintains sequences of computer instructions
required to solve a problem in such a way that if the
instructions are executed in the specified sequence, the
desired result is obtained.

5
Algorithm Development…
 E.g. Making a pot of tea
Step 1: Start
Step 2: If the kettle doesn’t contain water, then fill the kettle.
Step 3: Plug the kettle into the power point and switch it on.
Step 4: If the teapot is not empty, then empty the teapot.
Step 5: Place tea leaves in the teapot.
Step 6: If the water in the kettle is not boiling, then goto Step 3
Step 7: Switch off the kettle.
Step 8: Pour water from the kettle into the teapot.
Step 9: Stop

6
Algorithm Development…
• Any algorithm has following 3 features:
• Sequence (also known as process)
• Decision (also known as selection)
• Repetition (also known as iteration)

• Sequence
Sequence means that each step or process in the algorithm is executed in the
specified order………….A previous step must be executed before any
other next steps.

7
Algorithm Development…
• Decision
• If the outcome of the decision is true, then one thing is done
otherwise other thing is done. The outcome of decision is either true
or false; there is no state in between them.
• This decision is based on some condition.
• E.g. If a number is less than 0, then the no. is negative otherwise
positive.

The general form of a decision making statement is:


if condition then process1
OR
if condition
then process1
else process2

8
Algorithm Development…
• Repetition
• Repetition can be used by constructs like repeat loop, while loop, and
if…..then…..goto…..loop.
• The repeat loop is used to iterate or repeat a process or sequence of processes
until some condition is true.
Repeat
Process 1
Process 2
………
Process N
Until condition
E.g. Repeat
Fill water in the kettle
Until kettle is full

9
Algorithm Development…
• Problem of repeat loop
• If the kettle is already full at the start of Repeat loop??????

• While construct
• Check condition first and if outcome of condition is true, only then do
processes
While condition
Process 1
Process 2
………
Process N
End
E.g. While kettle is not full
Fill water in the kettle

10
Algorithm Development…
• if…..then…..goto…..loop
• The if…..then…..goto…..loop is also used to repeat a process or
sequence of processes until the given condition is false. Its general form
is:
Process 1
Process 2
……….
Process N
If condition then goto Process1

E.g.
Step1: Fill water in the kettle
Step 2: If kettle not full then goto Step1

11
Algorithm Development…
Some Coventions used in Developing Algorithms
 Each algorithm is enclosed by two statements START and STOP.
 To accept data from user, the INPUT or READ statement is used.
 To display any user message, the PRINT or DISPLAY statement is
used.
 The arithmetic operators (+, -, *, /) are used in expressions.
 The relational operators (>, >=, <, <=, ==, !=) are used in
conditions.
 The logical operators (AND, OR, NOT) are used for logical
expressions.

12
Problem 1: Write an algorithm for
finding the sum of any two numbers?
Algorithm

Step 1: Start
Step 2: Display “Enter two numbers”
Step 3: Read A and B
Step 4: C = A + B
Step 5: Display “C as sum of two numbers”
Step 6: Stop

13
Problem 2: Write an algorithm for
calculating the simple interest using
formula SI = (P*T*R)/100?

Algorithm

Step 1: Start
Step 2: Display “Enter values of P, T and R”
Step 3: Read P, T and R
Step 4: Calculate simple interest using formula, SI = (P*T*R)/100
Step 5: Display SI as simple interest
Step 6: Stop.

14
Problem 3: Write an algorithm to determine
whether a number is positive or negative?

Algorithm

Step 1: Start
Step 2: Print “Enter a no. that is to be tested for positive or negative”
Step 3: Read NUM from keyboard
Step 4: If NUM<0, then display message “The number is Negative” otherwise
display message “The number is Positive”
Step 5: Stop.

15
Problem 4: Write an algorithm to test
whether a number is even or odd?
Algorithm
Step 1: Start
Step 2: Display “Enter a number that is to be tested for even or odd”
Step 3: Read NUM from user
Step 4: Calculate remainder REM using integer division of NUM by
2
Step 5: If REM = 0, then print “The number is even”
else print “The number is odd”
Step 6: Stop

16
Problem 5: Write an algorithm to find the
largest number among three numbers?
Algorithm
Step 1: Start
Step 2: Display “Enter three numbers”
Step 3: Read A, B and C
Step 4: If A>=B and A>=C, then print “A is greatest”
Step 5: If B>=A and B>=C, then print “B is greatest” else print “C is
greatest”
Step 6: Stop

17
Problem 6: Write an algorithm to read N
numbers from user and display the sum of all
entered numbers?
Algorithm
Step 1: Start
Step 2: Print “How many numbers?”
Step 3: Read N
Step 4:Initialize variables SUM to 0 and COUNTER to 1 i.e. SUM=0 and
COUNTER=1
Step 5: Print “Enter a number”
Step 6: Read NUM
Step 7: SUM = SUM+NUM
Step 8: COUNTER = COUNTER + 1
Step 9: If COUNTER <= N, then goto Step 5
Step 10: Print SUM
Step 11: Stop

18
Problem 7: Write an algorithm for finding the
sum of the series 1+2+3+….. upto N terms
Algorithm
Step 1: Start
Step 2: Print “Enter the value of N”
Step 3: Read N
Step 4:Initialize variables SUM to 0 and COUNTER to 1 i.e. SUM=0 and
COUNTER=1
Step 5: SUM = SUM+COUNTER
Step 6: COUNTER = COUNTER + 1
Step 7: If COUNTER <= N, then goto Step 5
Step 8: Print SUM
Step 9: Stop

19
Problem 8: Write an algorithm for finding
the factorial of a given number?
Algorithm
Step 1: Start
Step 2: Print “Enter a number”
Step 3: Read NUM
Step 4:Initialize variables FACT to 1 and COUNTER to 1 i.e. SUM=1 and
COUNTER=1
Step 5: while COUNTER<=NUM
FACT=FACT*COUNTER
COUNTER=COUNTER+1
End of while
Step 8: Print FACT as factorial of the number NUM
Step 9: Stop

20
3) Flowchart
 Flowchart is the graphical representation of an algorithm
using standard symbols.
 Symbols used in flowchart are:

21
22
Advantages of Flowcharts
 Communication: They quickly and clearly provide logic, ideas and
descriptions of algorithms to other programmers, students, and
users.
 Effective Analysis: Flowcharts provide a clear overview of the
entire problem and its algorithm for solution. With the help of
flowcharts, problems can be analyzed more effectively.
 Proper Documentation: The flowchart provides a permanent
recording of program logic.
 Efficient Coding: A programmer can code the programming
instructions in a computer language with more ease with a
comprehensive flowchart.
 Easy in debugging and program maintenance

23
Limitations of Flowchart
 Complex Logic: A flowchart becomes complex and clumsy
when the program logic is quite complicated.
 Difficulty in alteration and modifications: If alterations are
required; the flowchart may need to be redrawn completely.

24
Guidelines in Flowcharting
 Only standard flowchart symbols are to be used.
 There should be Start and Stop to the flowchart.
 Only one flow line is used in conjunction with a Start and Stop
symbol.
 Only one flow line should emerge from a process symbol.
 Only one flow line should enter a decision symbol but two flow
lines, one for each possible answer, can leave the decision symbol.
 The contents of each symbol should be written legibly. English
should be used in flowcharts, not specific programming language.
 If the flowchart becomes complex, connector symbols should be
used to reduce the number of flow lines.

 Caution: No intersection of flow lines

25
4) Coding
 Coding is the act of transforming operations in each box of
the flowchart in terms of the statement of the programming
language.
 Coding is done using a programming language such as C.
 The code developed using a programming language is also
called source code.
 Coding must eliminate all syntax and logical errors.

26
5) Compilation and Execution
 The process of changing high level language into machine level
language is known as compilation. It is done by special software,
known as compiler.
 The compilation process tests the program whether it contains
syntax errors or not. If there are syntax errors, compiler cannot
compile the code.
 After successful compilation, the program is linked with other
object programs needed for execution, and then the program is
loaded in the memory for the purpose of execution and finally it is
executed.
 During execution, the program may ask for user inputs and
generates outputs after processing the inputs.

27
6) Debugging and Testing
 Debugging is the discovery and correction of programming
errors.
 These errors may appear during compilation or linking or
execution of the program. Whenever error appears, debugging is
necessary.
 Different Debugging tools are simulators, logic analyzers,
breakpoints, etc
 Testing ensures that program performs the required task correctly.
 For testing process, test data are supplied to the program and
output is observed. If the output is as expected, the program can
be considered error free.

28
7) Program Documentation
 Program documentation is description of the program and its
logic written to support understanding the program.
 Documentation of program helps to those who use, maintain and
extend the program in future.
 Two Types:
 Programmer’s Documentation (Technical Documentation)
 User Documentation (User Manual)

 Programmer’s documentation is prepared for future references to


the programmers who maintain, redesign and upgrade the
system.
 User documentation provides support to the user of the program.

29
Techniques for program documentation
 Diagrams such as Flowchart, DFD, E-R Diagram: A general
flowchart is a pictorial representation of a program. A
detailed flowchart expresses the flow of logic in a system
called DFD. E-R diagram can be used for database related
programs.
 Comments: Comments are a basic part of program
documentation (written in a program). These comments are
not compiled while compilation.
 Parameter and Definition Lists: Parameter and definition lists
explain the meaning and purpose of each parameter and
definition of each function.

30
Basic Structure of a C program
1) Documentation Section
2) Link Section
3) Definition Section
4) Global Declaration Section
5) main() function section
{
Declaration Part
Executable Part
}
6) Subprogram Section // User Defined Functions
Function 1
Function 2
…………
Function n

Note:- main() function is compulsory

31

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy