General Programming Concepts
Presented by Codeblix
Some Basic Terms
Algorithm
Algorithm / Flowchart
– A step-by-step procedure for solving a particul step procedure for
solving a particular problem. ar problem.
– Independent of the programming language.
Program
– A translation of the algorithm/flowchart into a form that can be
processed by a computer.
– Typically written in a high Typically written in a high-level language
like C, level language like C, C++, Java, etc
Variables and Constants
Variables and Constants
-All temporary results are stored in terms of variables
– The value of a variable can be changed.
– The value of a constant do not change.
Where are they stored?
– In main memory
Program
– A translation of the algorithm/flowchart into a form that can be
processed by a computer.
– Typically written in a high Typically written in a high-level language
like C, level language like C, C++, Java, etc
10 ?
y=20
10 20
x=y/4
5 20
y=x+2
5 7
X YInstructions
Three Common types of Data Type
-Integer :: can store only whole numbers
Examples: 25, -56, 1, 0
-Floating Floating-point :: can store numbers with fractional values.
Examples: 12345.345 , 5.0, 3.14159
– Character :: can store a character
Examples: ‘A’, ‘a’, ‘*’, ‘3’, ‘ ’, ‘+’
How are these Data Types stored in
Memory ?
– Integer ::
16 bits
32 bits
– Float ::
32 bits
64 bits
– Char ::
8 bits (ASCII code) 16 bits (UNICODE,
used in Java)
NOTE:
Actual number of bits vary from one
computer to another
Draw flowchart or write algorithm
Specify the problem to be solved
Execute the program
Convert flowchart (algorithm) into program code
Compile the program into object
code.
Problem Solving Technique
Adding three numbers
START
READ A, B, C
Sum= A+B+C
OUTPUT Sum
END
Larger Of two Numbers
START
READ X, Y
IS
X>Y?
YES NO
OUTPUT X OUTPUT Y
END END
Largest Of Three Numbers
START
READ X, Y, Z
IS
X>Y?
YES NO
MAX = X MAX = Y
IS
MAX>Z
?
YES NO
OUTPUT
MAX
OUTPUT
Z
END END
Sum Of First N Natural Numbers
START
READ N
SUM = 0
COUNT = 1
SUM = SUM + COUNT
COUNT = COUNT + 1
IS
COUNT >
N?
OUTPUT
SUM
END
NO YES
Sum = 12 + 22 + 32 + 42 + N2
START
READ N
SUM = 0
COUNT = 1
SUM = SUM + COUNT * COUNT
COUNT = COUNT + 1
IS COUNT
> N?
OUTPUT
SUM
END
NO YES
Sum = 1.2 + 2.3 + 3.4 + to N terms.
START
READ N
SUM = 0
COUNT = 1
SUM = SUM + COUNT * (COUNT + 1)
COUNT = COUNT + 1
IS COUNT
> N?
OUTPUT
SUM
END
NO YES
Computing Factorial
START
READ N
PROD = 1
COUNT = 1
PROD = PROD * COUNT
COUNT = COUNT + 1
IS COUNT
> N?
OUTPUT
PROD
END
NO YES
Computing ex series up to N
terms START
READ X, N
TERM = 1
SUM = 0
COUNT = 1
SUM = SUM + TERM
TERM = TERM * X/ COUNT
COUNT = COUNT + 1
IS COUNT
> N?
OUTPUT SUM
END
NO YES
Computing ex series upto 4 decimal places
START
READ X, N
TERM = 1
SUM = 0
COUNT = 1
SUM = SUM + TERM
TERM = TERM * X/ COUNT
COUNT = COUNT + 1
IS TERM <
0.0001 ?
OUTPUT SUM
END
NO YES
Roots of Quadratic Equation
ax2 + bx + c = 0
TRY YOURSELF
Grade Computation
MARKS ≥ 90
Ex
89 ≥ MARKS ≥ 80 A
79 ≥ MARKS ≥ 60 B
69 ≥ MARKS ≥ 60 C
59 ≥ MARKS ≥ 50 P
49 ≥ MARKS ≥ 35 F
Grade Computation ( Contd.)
START
READ MARKS
MARKS
≥ 90?
MARKS
≥ 80?
MARKS
≥ 70?
NO NO NO
OUTPUT
“Ex”
OUTPUT
“B”
OUTPUT
“A”
END END END
YES YES YES
CONTD.
MARK
S ≥ 60?
MARK
S ≥ 50?
MARK
S ≥ 35?
NO NO
OUTPUT
“C”
OUTPUT
“P”
OUTPUT
“D”
END END END
OUTPUT
“F”
END
NO
YES YES YES
CONTD.

Basic pogramming concepts

  • 1.
  • 2.
  • 3.
    Algorithm Algorithm / Flowchart –A step-by-step procedure for solving a particul step procedure for solving a particular problem. ar problem. – Independent of the programming language.
  • 4.
    Program – A translationof the algorithm/flowchart into a form that can be processed by a computer. – Typically written in a high Typically written in a high-level language like C, level language like C, C++, Java, etc
  • 5.
  • 6.
    Variables and Constants -Alltemporary results are stored in terms of variables – The value of a variable can be changed. – The value of a constant do not change. Where are they stored? – In main memory
  • 7.
    Program – A translationof the algorithm/flowchart into a form that can be processed by a computer. – Typically written in a high Typically written in a high-level language like C, level language like C, C++, Java, etc
  • 8.
    10 ? y=20 10 20 x=y/4 520 y=x+2 5 7 X YInstructions
  • 9.
    Three Common typesof Data Type -Integer :: can store only whole numbers Examples: 25, -56, 1, 0 -Floating Floating-point :: can store numbers with fractional values. Examples: 12345.345 , 5.0, 3.14159 – Character :: can store a character Examples: ‘A’, ‘a’, ‘*’, ‘3’, ‘ ’, ‘+’
  • 10.
    How are theseData Types stored in Memory ? – Integer :: 16 bits 32 bits – Float :: 32 bits 64 bits – Char :: 8 bits (ASCII code) 16 bits (UNICODE, used in Java) NOTE: Actual number of bits vary from one computer to another
  • 11.
    Draw flowchart orwrite algorithm Specify the problem to be solved Execute the program Convert flowchart (algorithm) into program code Compile the program into object code. Problem Solving Technique
  • 12.
    Adding three numbers START READA, B, C Sum= A+B+C OUTPUT Sum END
  • 13.
    Larger Of twoNumbers START READ X, Y IS X>Y? YES NO OUTPUT X OUTPUT Y END END
  • 14.
    Largest Of ThreeNumbers START READ X, Y, Z IS X>Y? YES NO MAX = X MAX = Y IS MAX>Z ? YES NO OUTPUT MAX OUTPUT Z END END
  • 15.
    Sum Of FirstN Natural Numbers START READ N SUM = 0 COUNT = 1 SUM = SUM + COUNT COUNT = COUNT + 1 IS COUNT > N? OUTPUT SUM END NO YES
  • 16.
    Sum = 12+ 22 + 32 + 42 + N2 START READ N SUM = 0 COUNT = 1 SUM = SUM + COUNT * COUNT COUNT = COUNT + 1 IS COUNT > N? OUTPUT SUM END NO YES
  • 17.
    Sum = 1.2+ 2.3 + 3.4 + to N terms. START READ N SUM = 0 COUNT = 1 SUM = SUM + COUNT * (COUNT + 1) COUNT = COUNT + 1 IS COUNT > N? OUTPUT SUM END NO YES
  • 18.
    Computing Factorial START READ N PROD= 1 COUNT = 1 PROD = PROD * COUNT COUNT = COUNT + 1 IS COUNT > N? OUTPUT PROD END NO YES
  • 19.
    Computing ex seriesup to N terms START READ X, N TERM = 1 SUM = 0 COUNT = 1 SUM = SUM + TERM TERM = TERM * X/ COUNT COUNT = COUNT + 1 IS COUNT > N? OUTPUT SUM END NO YES
  • 20.
    Computing ex seriesupto 4 decimal places START READ X, N TERM = 1 SUM = 0 COUNT = 1 SUM = SUM + TERM TERM = TERM * X/ COUNT COUNT = COUNT + 1 IS TERM < 0.0001 ? OUTPUT SUM END NO YES
  • 21.
    Roots of QuadraticEquation ax2 + bx + c = 0 TRY YOURSELF
  • 22.
    Grade Computation MARKS ≥90 Ex 89 ≥ MARKS ≥ 80 A 79 ≥ MARKS ≥ 60 B 69 ≥ MARKS ≥ 60 C 59 ≥ MARKS ≥ 50 P 49 ≥ MARKS ≥ 35 F
  • 23.
    Grade Computation (Contd.) START READ MARKS MARKS ≥ 90? MARKS ≥ 80? MARKS ≥ 70? NO NO NO OUTPUT “Ex” OUTPUT “B” OUTPUT “A” END END END YES YES YES CONTD.
  • 24.
    MARK S ≥ 60? MARK S≥ 50? MARK S ≥ 35? NO NO OUTPUT “C” OUTPUT “P” OUTPUT “D” END END END OUTPUT “F” END NO YES YES YES CONTD.