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

Some examples of Algorithm and Flowchart.

1. An algorithm and flowchart to generate sum of first N natural numbers.


Solution Algorithm
Step 1: Start
Step 2: Read an integer value i.e. N
Step 3: Assign, i=1.
Step 4: Calculate, Sum= Sum+ i. Increase i by 1.
Step 5: If i<=N then go to Step 4. Else go to step 6.
Step 6: Display Sum.
Step 7: End.
2. An algorithm and a flowchart to determine whether a given number is odd or even.
Solution Algorithm
Step 1: Start
Step 2: Read a number "n".
Step 3: Calculate, the remainder of n divided by 2 (i.e. n/2) that is rem=%2.
Step 4: If the rem=0 then Display "n" is even number and go to end. Else go to Step 5.
Step 5: Display "n" is odd.
Step 6: End.
3. Algorithm and flowchart to determine the largest of three given numbers.
Solution Algorithm
Step 1: Start.
Step 2: Read three numbers and store them as x, y, z.
Step 3: Compare x and y. If x is greater than y then go to step 6 else go to step 4.
Step 4: Compare y and z. If y is greater than z then print "y is largest" and go to step 8 otherwise go to step 5.
Step 5: Print "z is largest" and go to step 8.
Step 6: Compare x and z. If x is greater than z then print "x is largest" and go to step 7.
Step 7: Print "z is largest" and go to step 8.
Step 8: End

You might also like