Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
545 views

Programming Fundamentals: Bs-Cs 1 Semester

This document provides an introduction to programming fundamentals including problem solving, computer programs, algorithms, examples of algorithms, and flowcharts. It explains that problem solving involves identifying a problem and finding the best solution. Algorithms are step-by-step approaches to solve problems and are commonly written using pseudo code. Flowcharts represent algorithms visually using boxes and arrows. Examples of algorithms that calculate sums, areas, distances, and natural number sums are provided along with their corresponding flowcharts.

Uploaded by

Areeb
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
545 views

Programming Fundamentals: Bs-Cs 1 Semester

This document provides an introduction to programming fundamentals including problem solving, computer programs, algorithms, examples of algorithms, and flowcharts. It explains that problem solving involves identifying a problem and finding the best solution. Algorithms are step-by-step approaches to solve problems and are commonly written using pseudo code. Flowcharts represent algorithms visually using boxes and arrows. Examples of algorithms that calculate sums, areas, distances, and natural number sums are provided along with their corresponding flowcharts.

Uploaded by

Areeb
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Programming fundamentals

BS-CS 1st semester.


Prepared by: Syed Pir Zada
Lecturer in Computer Science
Problem solving
• Problem solving is a
process of identifying a
problem and finding the
best solution for it.
• It is a skill that can be
developed by following
a well organized
approach.
• We solve different
problems everyday.
Problem solving
• Every problem is different
in its nature.
• A problem may be solved
in different ways (multiple
solutions)
• One solution may be
faster, more reliable and
less expensive than
others.
• It is important to select
the best suitable solution.
Problem solving
• Different strategies, techniques and tools are
used to solve a problem.
• Computers are used to solve a problem by
developing computer programs.
• Computer programs contains different
instructions for computers.
• Different problem solving techniques are as
follows:
– Program
– Algorithm
– Flowchart
Computer program
• A set of instructions that tells the computer
what to do is called program.
• A computer works according to the given
instructions in the program.
• Computer programs are written in
programming languages.
• A person who develops a program is called
programmer.
Algorithm
• An algorithm is a step by step approach to
solve a problem.
• The process of solving a problem becomes
simpler and easier with the help of algorithm.
• It is better to write algorithm before the actual
program.
• Algorithms are written in a language that is
similar to simple English called pseudo code.
• There is no standard to write pseudo code.
Example 1
• The following algorithm inputs two numbers,
calculate sum and then display the result on the
screen.
1. Start
2. Input A
3. Input B
4. Total=A+B
5. Display Total
6. Exit
Example 2
• The following algorithm inputs radius from the
user and calculates the area of a circle.
1. Start
2. Input radius r
3. Area=3.14 * radius * radius
4. Print area
5. End
Example 3
• The following algorithm calculates the distance
covered by a car moving at an average speed of v
m/s in time t. it should input average speed v and
time t. (s=v*t)
1. Start
2. Input average speed in v
3. Input time in t
4. S=v*t
5. Print s
6. end
Example 4
• The following algorithm finds the sum of first 50
natural nos.
1. Start
2. Sum=0
3. N=1
4. Repeat step 5 and 6 while(N<=50)
5. Sum=sum+N
6. N=N+1
7. Print sum
8. End
Flowchart
• A flowchart is a diagram that represent an
algorithm or a process.
• It shows the steps of the algorithm with the
help of boxes and their orders by arrows.
• Flowcharts are used for analyzing, designing,
documenting or managing a process.
flowchart
– For example to find the average of five numbers.
1. Start
2. Sum=0, average=0
3. Read a,b,c,d,e
4. Sum=a+b+c+d+e
5. Average=sum/5
6. Print average
7. End
• Flowchart for the above algorithm
Start

READ
ABCDE

SUM=A+B+C+D+E
AVG=SUM/5

Print AVG

END
Adding two numbers

Start

Input A, B

Sum=A+B

Print Sum

END
Start

Input
Marks

No Yes
Marks>
=50

Display
Display
Pass
Fail

END
Start

Sum=0

N=1

SUM=SUM+N

N=N+1

IS
Yes N<=50
?
No
Print Sum

End

You might also like