Examples - Algorithm, Flowchart and Pseudo code

 

Examples

Write Algorithm, Flowchart and Pseudo code

1.Area and Circumference of the circle

Step 1: Start
Step 2: Read radius r
Step 3: Calculate area A=3.14*r*r
Step 4: Calculate circumference C=2*3.14*r
Step 5: Display A,C
Step 6: Stop


BEGIN
READ r
CALCULATE A and C
A=3.14*r*r
C=2*3.14*r
DISPLAY A, C
END

2.To check greatest of two numbers a,b

Step 1: Start
Step 2: Get a,b value
Step 3: check if(a>b) print 'a is greater'
Step 4: else print 'b is greater'
Step 5: Stop


BEGIN
READ a,b
IF (a>b) THEN
    DISPLAY 'a is greater'
ELSE
    DISPLAY 'b is greater'
END IF
END

To check greatest of three numbers A,B,C

Step1: Start
Step2: Get A, B, C
Step3: if(A>B) goto Step4 else goto step5
Step4: If(A>C) print A else print C
Step5: If(B>C) print B else print C
Step6: Stop




















BEGIN
READ a, b, c

IF (a>b) THEN
    IF(a>c) THEN
            DISPLAY a is greater
    ELSE
        DISPLAY c is greater
    END IF
ELSE
    IF(b>c) THEN
            DISPLAY b is greater
    ELSE
        DISPLAY c is greater
    END IF
END IF
END

Print odd numbers upto n

step 1: start
step 2: get n value
step 3: set initial value i=1
step 4: check if(i<=n) goto step 5 else goto step 8
step 5: print i value
step 6: increment i value by 2
step 7: goto step 4
step 8: stop



















BEGIN
GET n
INITIALIZE i=1
WHILE(i<=n) DO
    PRINT i
    i=i+2
ENDWHILE
END

Factorial of a given number

Step 1: start
step 2: get n value
step 3: set initial value i=1, fact=1
Step 4: check i value if(i<=n) goto step 5 else goto step8
step 5: calculate fact=fact*i
step 6: increment i value by 1
step 7: goto step 4
step 8: print fact value
step 9: stop























BEGIN
GET n
INITIALIZE i=1,fact=1
WHILE(i<=n) DO
    fact=fact*i
    i=i+1
ENDWHILE
PRINT fact
END

If the three sides of a triangle are input, write an algorithm/pseudocode to check whether the triangle is isosceles, equilateral, or scalene ( University Question)
Step 1: Start
Step 2: Input side1, side2, side3
Step 3: Check if the three sides can form a triangle
        IF (side1 + side2 > side3) AND 
           (side2 + side3 > side1) AND 
           (side1 + side3 > side2) THEN
              Proceed
        ELSE
              Print "Not a valid triangle"
              Stop
Step 4: IF side1 = side2 AND side2 = side3 THEN
              Print "Equilateral Triangle"
        ELSE IF side1 = side2 OR side2 = side3 OR side1 = side3 THEN
              Print "Isosceles Triangle"
        ELSE
              Print "Scalene Triangle"
Step 5: Stop

Write pseudo code to determine the average age of students in a class. The user will stop giving the input by giving the age as 0. (University question)
Step 1: Start
Step 2: Initialize sum ← 0, count ← 0
Step 3: Repeat
            Input age
            IF age ≠ 0 THEN
                  sum ← sum + age
                  count ← count + 1
        Until age = 0
Step 4: IF count > 0 THEN
            average ← sum / count
            Print "Average age = ", average
        ELSE
            Print "No ages entered"
Step 5: Stop

University question
You visit a shop to buy a new mobile. In connection with the festive season, the shop offers a 10% discount on all mobiles. In addition, the shop also gives a flat exchange price of 1000 for old mobiles. Draw a flowchart to input the original price of the mobile and print its selling price. Note that all customers may not have an old mobile for exchange. ( University Question)



Write pseudo code to determine the average age of students in a class. The user will stop giving the input by giving the age as 0. ( University Question)

1 Start
2 sum = 0
3 count = 0
4 Read(age)
5 while (age!=0)
6 sum = sum + age
7 count = count + 1
8 Read(age)
9 end while
10 average = sum/count
11 Print(average)
12 Stop

Draw a flowchart to find the largest number from a series of numbers entered sequentially.


Draw the flowchart to generate the first 'n' numbers in the Fibonacci sequence.

Draw a flowchart to print the numbers that are divisible by 4 but not by 3 in a list of n positive numbers




Comments

Popular posts from this blog

Algorithmic Thinking with Python UCEST 105- KTU First Semester BTech Course 2024 scheme notes pdf - Dr Binu V P 9847390760

Lab Experiments and Solutions - Algorithmic thinking with Python KTU S1 2024 scheme

PadLocking