Algorithms and Flowcharts
This document contains algorithms and flowcharts for
the following problems:
1. Exchanging the values of two variables
2. Counting from 1 to n
3. Summation of a set of numbers
4. Factorial computation
1. Exchanging the values of two variables
Algorithm:
1. Start
2. Input two variables A and B
3. Display the values of A and B before exchange
4. Set TEMP = A
5. Set A = B
6. Set B = TEMP
7. Display the values of A and B after exchange
8. Stop
Flowchart:
Start → Input A,B → TEMP=A → A=B → B=TEMP →
Display A,B → Stop
2. Counting from 1 to n
Algorithm:
1. Start
2. Input N
3. Set I = 1
4. While I ≤ N, do
Display I
Increment I by 1
5. Stop
Flowchart:
Start → Input N → I=1 → [I ≤ N?] → Yes → Display I →
I=I+1 → Back to check → No → Stop
3. Summation of a set of numbers
Algorithm:
1. Start
2. Input the value of N (total numbers)
3. Set SUM = 0 and I = 1
4. While I ≤ N, do
Input number X
SUM = SUM + X
I=I+1
5. Display SUM
6. Stop
Flowchart:
Start → Input N → SUM=0, I=1 → [I ≤ N?] → Yes → Input
X → SUM=SUM+X → I=I+1 → Back to check → No →
Display SUM → Stop
4. Factorial Computation
Algorithm:
1. Start
2. Input N
3. Set FACT = 1 and I = 1
4. While I ≤ N, do
FACT = FACT × I
I=I+1
5. Display FACT
6. Stop
Flowchart:
Start → Input N → FACT=1, I=1 → [I ≤ N?] → Yes →
FACT=FACT×I → I=I+1 → Back to check → No → Display
FACT → Stop