Sie sind auf Seite 1von 12

Algorithms and Flowcharts

1. Sum of two numbers


STEP 1 : START
STEP 2 : ACCEPT FIRST NUMBER
STEP 3 : ACCEPT SECOND NUMBER
STEP 4 : ADD THESE TWO NUMBERS
STEP 5 : DISPLAY RESULT
STEP 6 : STOP
2. Largest among three numbers
Step 1: Start
Step 2: Declare variables a,b and c.
Step 4: If a>b && a>c then goto step 7,othervise goto step 5
Step 5: if b>a && b>c then goto step 8, othervise goto step 6
Step 6: print c is greater goto step9
Step 7: print a is gresater goto step9
Step 8: print b is greater goto step9
Step 9: stop
3. Area of Rectangle
STEP 1: START
STEP 2: ACCEPT THE WOF RECTANGLE
STEP 3: ACCEPT THE H OF RECTANGLE
STEP 4: Area = w h
STEP 5: DISPLAY Area
STEP 6: STOP
4. Sum of digits
Step 1: start
Step 2: read n
Step 3: initialize the s=0
Step 4: if n<0 goto Step 7
Step 5: if n!=0 goto Step 6 else goto step 7
Step 6:
6.a. store n%10 value in p
6.b. Add p value to s
6.c. Assign n/10 value to n
6.d. Goto Step 5
Step 7: print s
Step 8:stop
5. Reversing a given number

Step 1: Start
Step 2: Read num
Step 3: Initialize rev_num = 0
Step 4: Repeat while num > 0
(a) Calculate remainder = num mod 10
(b) Multiply rev_num by 10 and add remainder
(c) divide num by 10
Step 5: Display rev_num
6. Factorial of a number
Step1:Start
Step2:Read the number.
Step3:Intialize i=1,Fact=1
Step4:Repeat steps 4 through6 until i=n
Step5:Fact=Fact*i
Step6:i=i+1
Step7:print Fact
Step8:Stop
7. Fibonacci series

Step 1: start
Step 2: initialize the a=0, b=1
Step 3: read n
Step 4: if n== 1 print a go to step 7. else goto step 5
Step 5: if n== 2 print a, b go to step 7 else print a,b
Step 6: initialize i=3
i) if i<= n do as follows. If not goto step 7
c=a+b
print c
a=b
b=c
increment I value
ii)goto step 6(i)
Step 7: stop
8. Checking whether a number is prime or not

Step 1: Start
Step 2: Declare variables n,i,flag.
Step 3: Initialize variables flag=1, i=2
Step 4: Read n from user.
Step 5: Repeat the steps until i<(n/2)
5.1 If (n mod i) = 0
Set flag=0 and go to step 6
5.2 ii+1
Step 6: If flag=0
Display n is not prime
else
Display n is prime
Step 7: Stop
9. Prime numbers upto N

Step 1: start
Step 2: read n
Step 3: initialize i=1,c=0
Step 4:if i<=n goto step 5. If not goto step 10
Step 5: initialize j=1
Step 6: if j<=1 do as the follow. If no goto step 7
i)if i%j==0 increment c
ii) increment j
iii) goto Step 6
Step 7: if c== 2 print i
Step 8: increment i
Step 9: goto step 4
Step 10: stop
10. Roots of Quadratic Equation

Step 1: start
Step 2: read the a,b,c value
Step 3: if b*b-4ac>0 then
Root 1= (-b+ pow((b*b-4*a*c),0.5))/2*a
Root 2= (-b-pow((b*b-4*a*c),0.5))/2*a
Step 4: if b*b-4ac=0 then
Root1 = Root2 = -b/(2*a)
Step 5: Otherwise Print Imaginary roots. Goto step 7.
Step 6: print roots
Step 7: stop
11. Maximum/Largest element in a list/an array

Step 1: SET Max to array[0]


Step 2: SET i to 1
Step 3: while i< n, do
3.a)IF array[i] > Max THEN
SET Max to array[i]
3.b)i = i+1
Step 4:PRINT Max
12. GCD of 2 numbers

Step 1: Read num1, num2


Step 2: If num2=0, return the value of num1 as the answer and stop; otherwise,
proceed to step 3.
Step 3: Assign r as num1 mod num2
Step 4: Assign the value of num2 to num1 and the value of r to num2. Go to step 2.

Das könnte Ihnen auch gefallen