Lecture 1 Introduction To Programming

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 14

INTRODUCTION TO

COMPUTER
PROGRAMMING

1
Introduction to Programming
Program: The term program refers to a set of instructions
that instructs a computer on what to do. Programs are
Solutions to Problems, and they are written using
programming languages.
•A program can instruct a computer to:
– Read/ accept Input data
– Calculate or compare
– Store data
– Write or display Output and communication messages.

2
ALGORITHM
SEQUENCE OF STEPS TO SOLVE THE PROBLEMS

3
ALGORITHM
SEQUENCE OF STEPS TO SOLVE THE PROBLEMS

4
Advantages of algorithm

• It is a step-wise representation of a solution to a given problem,


which makes it easy to understand.
• An algorithm uses a definite procedure.
• It is not dependent on any programming language, so it is easy to
understand for anyone even without programming knowledge.
• Every step in an algorithm has its own logical sequence so it is easy
to debug.

5
FLOWCHART

A flowchart is
a graphical
representation
of steps.

6
7
8
Advantages of flowchart:

• Flowchart is an excellent way of communicating the logic of a


program.

• Easy and efficient to analyze problem using flowchart.

• During program development cycle, the flowchart plays the role of


a blueprint, which makes program development process easier.

• After successful development of a program, it needs continuous


timely maintenance during the course of its operation. The
flowchart makes program or system maintenance easier.

• It is easy to convert the flowchart into any programming language


code.

9
DECISION STRUCTURES
• The structure is as follows

If condition then

true alternative

else
false alternative
endif

10
Example 1: Write an algorithm to determine a student’s final grade and
indicate whether it is passing or failing. The final grade is calculated as the
average of four marks.

1. Input a set of 4 marks


2. Calculate their average by
summing and dividing by 4
3. if average is below 50
4. Print “FAIL” else Print “PASS”

Step 1: Input M1,M2,M3,M4


Step 2: GRADE (M1+M2+M3+M4)/4
Step 3: if (GRADE <50 )
Step 4: PRINT “ FAIL”
ELSE
PRINT “ PASS “

11
Example 2 Write an algorithm and draw a flowchart to convert the length
in feet to centimeter.

1. Input the length in feet (Lft)


2. Calculate the length in cm (Lcm)
by multiplying LFT with 30
3. Print length in cm (LCM)

Step 1: Input Lft


Step 2: Lcm Lft x 30
Step 3: Print Lcm

12
13
PRACTICE QUESTIONS

1. Write an algorithm and draw a flowchart that will read the two sides of a
rectangle and calculate its area.

2. Algorithm & Flowchart to find the sum of two numbers

3. Algorithm & Flowchart to convert temperature from Celsius to Fahrenheit

4. Algorithm & Flowchart to find Area and Perimeter of Circle

14

You might also like