Algorithms and Flowcharts
Algorithms and Flowcharts
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