KEMBAR78
Introduction to programming : flowchart, algorithm | PDF
Introduction to Programming
Programming is the process of telling a computer what to do using a specific language it
understands. It helps us create software, apps, games, websites, and more!
1. Basic Model of Computation
At its core, a computer works like a machine that:
 Takes Input (from keyboard, mouse, files, etc.)
 Processes it using logic (calculations, decisions)
 Produces Output (on screen, in files, etc.)
This basic model is often described as:
arduino
CopyEdit
INPUT → PROCESS → OUTPUT
Example:
You enter two numbers → Computer adds them → It shows the result.
2. What is an Algorithm?
An algorithm is a step-by-step set of instructions to solve a problem.
Think of it like a recipe:
 Input: Ingredients
 Steps: Mixing, baking
 Output: Cake
Example Algorithm to add two numbers:
1. Start
2. Input two numbers A and B
3. Add A + B and store in SUM
4. Output SUM
5. End
3. What is a Flowchart?
A flowchart is a visual diagram that shows the steps of an algorithm using symbols and arrows.
✨Common Flowchart Symbols:
Symbol Shape Purpose
Oval Start/End
Diamond Decision (Yes/No)
Rectangle Process/Step
Parallelogram Input/Output
➡ Arrow Shows flow
Flowcharts help visualize how a program works before writing code.
4. What is a Programming Language?
A programming language is a special language used to write instructions for a computer.
Some Common Languages:
 Python – easy and beginner-friendly
 C/C++ – powerful and fast
 Java – commonly used for apps
 JavaScript – used in websites
Each language has its own rules (syntax), but all are used to write logic (algorithms).
⚙ 5. Compilation
Compilation is the process of converting your code (which humans understand) into machine
code (which computers understand).
 Source Code → Written by the programmer (e.g., in C)
 Compiler → Converts it into machine language (binary)
 Executable → File the computer can run
Some languages like Python use an interpreter instead of a compiler.
6. Testing and Debugging
After writing your code, you must check that it works properly.
 Testing: Run your program with different inputs to see if it gives correct results.
 Debugging: Finding and fixing errors (bugs) in your program.
There are 3 types of errors:
Type Meaning
Syntax Error Mistake in code structure (e.g., missing colon)
Logic Error Code runs, but gives wrong result
Runtime Error Error occurs while running (e.g., divide by zero)
7. Documentation
Documentation means writing clear explanations about:
 What the program does
 How it works
 How to use it
It helps others (and your future self) understand your code. Good documentation includes:
 Comments in the code
 User guides
 Design notes
Summary Table
Concept What It Means
Model of Computation Input → Process → Output
Algorithm Step-by-step instructions
Flowchart Visual way to show steps
Programming Language Used to write programs
Compilation Converts code into machine language
Testing Checking if program works
Debugging Fixing problems in code
Documentation Explaining what the program does
What is Pseudocode?
Pseudocode is like writing down the steps of a program in plain English. It’s not real code, but
it shows how the code should work. You don’t worry about exact syntax (like commas or
brackets), just the logic.
✅Why Use Pseudocode?
 Helps you plan your code before writing it
 Easy to understand, even if you don’t know a programming language yet
 Makes it easier to spot mistakes
 Helps you explain your program to others
✍ How to Write Pseudocode
Use simple steps and common keywords. Here's a quick guide:
Task Pseudocode Keyword
Task Pseudocode Keyword
Start or end BEGIN, END
Take user input INPUT
Show a message OUTPUT or DISPLAY
Set a variable SET or ASSIGN
Make a choice IF, THEN, ELSE
Repeat steps WHILE, FOR
Use another function CALL
Example:
plaintext
CopyEdit
BEGIN
INPUT number
IF number > 0 THEN
OUTPUT "Positive"
ELSE
OUTPUT "Not positive"
END
What is a Flowchart?
A flowchart is a picture that shows the steps in a program using shapes and arrows. It’s a visual
way to understand how a program works.
Common Flowchart Symbols
Symbol Shape Use
Start/End Oval Shows where the program starts or ends
Process Rectangle A step that does something (like a calculation)
Decision Diamond A question with yes/no answers
Input/Output Parallelogram For reading input or showing output
Arrow ➡ Line Shows the direction of steps
How to Use Flowcharts
1. Start with the "Start" symbol
2. Add steps (input, processing, decisions)
3. Use arrows to show the order
4. End with the "End" symbol
Example: Password Checker
Goal: Check if a password is:
 At least 8 characters long
 Contains at least one number
✅Valid Passwords:
 super123
 meandmy2dogs
❌Invalid Passwords:
 hello (too short)
 password (no number)
Pseudocode for Password Checker
plaintext
CopyEdit
BEGIN
INPUT password
SET length = 0
SET has_number = False
WHILE length < length of password
SET current = character at position length
INCREMENT length by 1
IF current is a number THEN
SET has_number = True
IF length >= 8 AND has_number is True THEN
OUTPUT "Valid Password"
ELSE
OUTPUT "Invalid Password"
END
Flowchart (Explanation)
1. Start
2. Input the password
3. Check each character:
o Count the length
o Check if it’s a number
4. After checking:
o If length ≥ 8 AND there is a number → Valid
o Else → Invalid
5. End
Why Use Both Pseudocode & Flowcharts?
Using both gives you:
 Text view (pseudocode) for programmers
 Visual view (flowchart) for better understanding
 Helps in team projects, planning, and learning
❓ FAQs - Quick Answers
Q: Is pseudocode real code?
A: No, it's a way to describe code in plain English.
Q: Who uses pseudocode?
A: Students, programmers, teachers — anyone planning or learning code.
Q: What’s the difference between an algorithm and a flowchart?
A: An algorithm is a list of steps; a flowchart shows those steps as a picture.
Q: Is pseudocode hard?
A: Not at all! If you can explain what a program should do in plain words, you can write
pseudocode.
Flowchart Symbols (Basics)
Symbol Shape Meaning
Symbol Shape Meaning
Start/End Oval Marks where the flow starts or ends
Input/Output Parallelogram Reads or displays data
Process Rectangle A calculation or assignment
Decision Diamond A Yes/No (True/False) condition
Arrow ➡ Line Shows the flow from step to step
Types of Algorithm/Flowchart Processing
1. Sequential Processing
 Steps are done one after another in order.
2. Decision-Based Processing
 The program chooses a path based on a condition (like if-else).
3. Iterative Processing
 Loops are used to repeat steps (like for, while).
Basic Algorithm + Flowchart Examples
1. Exchanging Values of Two Variables
Algorithm:
1. Input A, B
2. Temp = A
3. A = B
4. B = Temp
5. Output A, B
Flowchart Keywords: Input → Process → Output
➕2. Summation of N Numbers
Algorithm:
1. Input N
2. Set Sum = 0
3. Repeat from i = 1 to N:
o Input number
o Sum = Sum + number
4. Output Sum
Flowchart Type: Iterative
3. Decimal to Binary Conversion
Algorithm:
1. Input decimal number n
2. While n > 0:
o Remainder = n % 2
o Store remainder
o n = n // 2
3. Print remainders in reverse order
Flowchart Type: Iterative + Stack logic (store remainders)
4. Reversing Digits of an Integer
Algorithm:
1. Input number n
2. Set reverse = 0
3. While n > 0:
o digit = n % 10
o reverse = reverse * 10 + digit
o n = n // 10
4. Output reverse
5. GCD of Two Numbers
Algorithm (Euclid’s Method):
1. Input A, B
2. While B ≠ 0:
o Temp = B
o B = A % B
o A = Temp
3. Output A (GCD)
6. Test if a Number is Prime
Algorithm:
1. Input number n
2. If n < 2 → Not Prime
3. Check if any number from 2 to √n divides n
o If yes → Not Prime
o Else → Prime
❗ 7. Factorial of a Number
Algorithm:
1. Input n
2. Set fact = 1
3. For i = 1 to n:
o fact = fact * i
4. Output fact
8. Fibonacci Sequence
Algorithm:
1. Input n
2. Set a = 0, b = 1
3. For i = 1 to n:
o Print a
o next = a + b
o a = b
o b = next
9. Evaluate sin(x) Using Series
Use the Taylor Series:
sin(x) = x - x³/3! + x⁵/5! - x⁷/7! + ...
Algorithm:
1. Input x, number of terms
2. Set sign = 1, sinx = 0, term = x
3. Repeat with increasing odd powers and alternating signs
4. Output sinx
10. Reverse Order of Elements in an Array
Algorithm:
1. Input array A[0...n-1]
2. Set start = 0, end = n-1
3. While start < end:
o Swap A[start] and A[end]
o start++, end--
4. Output array
11. Find Largest Number in an Array
Algorithm:
1. Input array A[0...n-1]
2. Set max = A[0]
3. For i = 1 to n-1:
o If A[i] > max → max = A[i]
4. Output max
12. Print Elements of Upper Triangular Matrix
For matrix A[i][j], upper triangle includes elements where i ≤ j
Algorithm:
1. Input matrix A[n][n]
2. For i = 0 to n-1:
o For j = 0 to n-1:
 If i ≤ j → Print A[i][j]
 Else → Print 0
✅Summary Chart
Problem Type of Processing
Swap Two Numbers Sequential
Sum of Numbers Iterative
Decimal to Binary Iterative
Reverse Digits Iterative
GCD Iterative (with condition)
Prime Test Decision + Iterative
Factorial Iterative
Fibonacci Iterative
sin(x) Iterative
Reverse Array Iterative
Largest in Array Iterative + Decision
Upper Triangular Matrix Nested Iteration + Condition

Introduction to programming : flowchart, algorithm

  • 1.
    Introduction to Programming Programmingis the process of telling a computer what to do using a specific language it understands. It helps us create software, apps, games, websites, and more! 1. Basic Model of Computation At its core, a computer works like a machine that:  Takes Input (from keyboard, mouse, files, etc.)  Processes it using logic (calculations, decisions)  Produces Output (on screen, in files, etc.) This basic model is often described as: arduino CopyEdit INPUT → PROCESS → OUTPUT Example: You enter two numbers → Computer adds them → It shows the result. 2. What is an Algorithm? An algorithm is a step-by-step set of instructions to solve a problem. Think of it like a recipe:  Input: Ingredients  Steps: Mixing, baking  Output: Cake Example Algorithm to add two numbers: 1. Start 2. Input two numbers A and B 3. Add A + B and store in SUM 4. Output SUM 5. End
  • 2.
    3. What isa Flowchart? A flowchart is a visual diagram that shows the steps of an algorithm using symbols and arrows. ✨Common Flowchart Symbols: Symbol Shape Purpose Oval Start/End Diamond Decision (Yes/No) Rectangle Process/Step Parallelogram Input/Output ➡ Arrow Shows flow Flowcharts help visualize how a program works before writing code. 4. What is a Programming Language? A programming language is a special language used to write instructions for a computer. Some Common Languages:  Python – easy and beginner-friendly  C/C++ – powerful and fast  Java – commonly used for apps  JavaScript – used in websites Each language has its own rules (syntax), but all are used to write logic (algorithms). ⚙ 5. Compilation Compilation is the process of converting your code (which humans understand) into machine code (which computers understand).
  • 3.
     Source Code→ Written by the programmer (e.g., in C)  Compiler → Converts it into machine language (binary)  Executable → File the computer can run Some languages like Python use an interpreter instead of a compiler. 6. Testing and Debugging After writing your code, you must check that it works properly.  Testing: Run your program with different inputs to see if it gives correct results.  Debugging: Finding and fixing errors (bugs) in your program. There are 3 types of errors: Type Meaning Syntax Error Mistake in code structure (e.g., missing colon) Logic Error Code runs, but gives wrong result Runtime Error Error occurs while running (e.g., divide by zero) 7. Documentation Documentation means writing clear explanations about:  What the program does  How it works  How to use it It helps others (and your future self) understand your code. Good documentation includes:  Comments in the code  User guides  Design notes Summary Table
  • 4.
    Concept What ItMeans Model of Computation Input → Process → Output Algorithm Step-by-step instructions Flowchart Visual way to show steps Programming Language Used to write programs Compilation Converts code into machine language Testing Checking if program works Debugging Fixing problems in code Documentation Explaining what the program does What is Pseudocode? Pseudocode is like writing down the steps of a program in plain English. It’s not real code, but it shows how the code should work. You don’t worry about exact syntax (like commas or brackets), just the logic. ✅Why Use Pseudocode?  Helps you plan your code before writing it  Easy to understand, even if you don’t know a programming language yet  Makes it easier to spot mistakes  Helps you explain your program to others ✍ How to Write Pseudocode Use simple steps and common keywords. Here's a quick guide: Task Pseudocode Keyword
  • 5.
    Task Pseudocode Keyword Startor end BEGIN, END Take user input INPUT Show a message OUTPUT or DISPLAY Set a variable SET or ASSIGN Make a choice IF, THEN, ELSE Repeat steps WHILE, FOR Use another function CALL Example: plaintext CopyEdit BEGIN INPUT number IF number > 0 THEN OUTPUT "Positive" ELSE OUTPUT "Not positive" END What is a Flowchart? A flowchart is a picture that shows the steps in a program using shapes and arrows. It’s a visual way to understand how a program works. Common Flowchart Symbols Symbol Shape Use Start/End Oval Shows where the program starts or ends Process Rectangle A step that does something (like a calculation) Decision Diamond A question with yes/no answers Input/Output Parallelogram For reading input or showing output Arrow ➡ Line Shows the direction of steps How to Use Flowcharts 1. Start with the "Start" symbol 2. Add steps (input, processing, decisions)
  • 6.
    3. Use arrowsto show the order 4. End with the "End" symbol Example: Password Checker Goal: Check if a password is:  At least 8 characters long  Contains at least one number ✅Valid Passwords:  super123  meandmy2dogs ❌Invalid Passwords:  hello (too short)  password (no number) Pseudocode for Password Checker plaintext CopyEdit BEGIN INPUT password SET length = 0 SET has_number = False WHILE length < length of password SET current = character at position length INCREMENT length by 1 IF current is a number THEN SET has_number = True IF length >= 8 AND has_number is True THEN OUTPUT "Valid Password" ELSE OUTPUT "Invalid Password" END Flowchart (Explanation)
  • 7.
    1. Start 2. Inputthe password 3. Check each character: o Count the length o Check if it’s a number 4. After checking: o If length ≥ 8 AND there is a number → Valid o Else → Invalid 5. End Why Use Both Pseudocode & Flowcharts? Using both gives you:  Text view (pseudocode) for programmers  Visual view (flowchart) for better understanding  Helps in team projects, planning, and learning ❓ FAQs - Quick Answers Q: Is pseudocode real code? A: No, it's a way to describe code in plain English. Q: Who uses pseudocode? A: Students, programmers, teachers — anyone planning or learning code. Q: What’s the difference between an algorithm and a flowchart? A: An algorithm is a list of steps; a flowchart shows those steps as a picture. Q: Is pseudocode hard? A: Not at all! If you can explain what a program should do in plain words, you can write pseudocode. Flowchart Symbols (Basics) Symbol Shape Meaning
  • 8.
    Symbol Shape Meaning Start/EndOval Marks where the flow starts or ends Input/Output Parallelogram Reads or displays data Process Rectangle A calculation or assignment Decision Diamond A Yes/No (True/False) condition Arrow ➡ Line Shows the flow from step to step Types of Algorithm/Flowchart Processing 1. Sequential Processing  Steps are done one after another in order. 2. Decision-Based Processing  The program chooses a path based on a condition (like if-else). 3. Iterative Processing  Loops are used to repeat steps (like for, while). Basic Algorithm + Flowchart Examples 1. Exchanging Values of Two Variables Algorithm: 1. Input A, B 2. Temp = A 3. A = B 4. B = Temp 5. Output A, B Flowchart Keywords: Input → Process → Output ➕2. Summation of N Numbers
  • 9.
    Algorithm: 1. Input N 2.Set Sum = 0 3. Repeat from i = 1 to N: o Input number o Sum = Sum + number 4. Output Sum Flowchart Type: Iterative 3. Decimal to Binary Conversion Algorithm: 1. Input decimal number n 2. While n > 0: o Remainder = n % 2 o Store remainder o n = n // 2 3. Print remainders in reverse order Flowchart Type: Iterative + Stack logic (store remainders) 4. Reversing Digits of an Integer Algorithm: 1. Input number n 2. Set reverse = 0 3. While n > 0: o digit = n % 10 o reverse = reverse * 10 + digit o n = n // 10 4. Output reverse 5. GCD of Two Numbers Algorithm (Euclid’s Method):
  • 10.
    1. Input A,B 2. While B ≠ 0: o Temp = B o B = A % B o A = Temp 3. Output A (GCD) 6. Test if a Number is Prime Algorithm: 1. Input number n 2. If n < 2 → Not Prime 3. Check if any number from 2 to √n divides n o If yes → Not Prime o Else → Prime ❗ 7. Factorial of a Number Algorithm: 1. Input n 2. Set fact = 1 3. For i = 1 to n: o fact = fact * i 4. Output fact 8. Fibonacci Sequence Algorithm: 1. Input n 2. Set a = 0, b = 1 3. For i = 1 to n: o Print a o next = a + b o a = b o b = next
  • 11.
    9. Evaluate sin(x)Using Series Use the Taylor Series: sin(x) = x - x³/3! + x⁵/5! - x⁷/7! + ... Algorithm: 1. Input x, number of terms 2. Set sign = 1, sinx = 0, term = x 3. Repeat with increasing odd powers and alternating signs 4. Output sinx 10. Reverse Order of Elements in an Array Algorithm: 1. Input array A[0...n-1] 2. Set start = 0, end = n-1 3. While start < end: o Swap A[start] and A[end] o start++, end-- 4. Output array 11. Find Largest Number in an Array Algorithm: 1. Input array A[0...n-1] 2. Set max = A[0] 3. For i = 1 to n-1: o If A[i] > max → max = A[i] 4. Output max 12. Print Elements of Upper Triangular Matrix For matrix A[i][j], upper triangle includes elements where i ≤ j Algorithm: 1. Input matrix A[n][n]
  • 12.
    2. For i= 0 to n-1: o For j = 0 to n-1:  If i ≤ j → Print A[i][j]  Else → Print 0 ✅Summary Chart Problem Type of Processing Swap Two Numbers Sequential Sum of Numbers Iterative Decimal to Binary Iterative Reverse Digits Iterative GCD Iterative (with condition) Prime Test Decision + Iterative Factorial Iterative Fibonacci Iterative sin(x) Iterative Reverse Array Iterative Largest in Array Iterative + Decision Upper Triangular Matrix Nested Iteration + Condition