Algorithms
Algorithms
1. Start
2. Declare necessary variables
3. Input age
4. If age>=18, then print “Eligible to vote”
Else print “Ineligible to vote”
5. Stop
1. Start
2. Declare necessary variables
3. Input marks
4. If marks>=80 and marks<=100, then grade = ‘A’: go to 7
5. If marks>=60 and marks<80, then grade = ‘B’: go to 7
6. If marks>=40 and marks<60, then grade = ‘C’, else grade
= ‘D’
7. Print grade
8. Stop
1. Start
2. Declare necessary variables
3. Input two numbers
4. Input operation
5. If operation=’+’, then add the numbers
6. If operation=’-‘, then subtract the numbers
7. If operation=’*’, then multiply the numbers
8. If operation=’/’, then divide the numbers
9. Default: print “invalid input” and exit
10. Print output
11. Stop
1. Start
2. Declare necessary variables
3. Input choice
4. If choice=1: go to 5, else go to 7
5. Input num
6. If num%10==7 and num%7==0, then print “Buzz
number”, else print “Not a Buzz number”
7. Input num1 and num2
8. Find the smaller number, and store it in small
9. For i --> 1 to small
10. If num1%i==0 and num2%i==0, then HCF=i
11. End loop
12. LCM=(num1*num2)/HCF
13. Print output
14. Default: print “Invalid input” and exit
15. Stop
1. Start
2. Declare necessary variables
3. Input number
4. for i 2 to <n
5. if n%i==0, flag=1
6. End loop
7. If flag==1, print “Composite number”, else print “Prime
number”
8. Stop
1. Start
2. Declare necessary variables, initialize space=3
3. For i 1 to <=4
For j 1 to <=space, Print “ “
For k 1 to <=I, Print k
For li-1 to l>=1, Print l
Print a new line
Decrease space by 1
4. End loop
5. Initialize space=1
6. For i 3 to >=1
For j 1 to <=space, Print “ “
For k 1 to <=I, Print k
For li-1 to l>=1, Print l
Increase space by 1
7. End loop
8. Stop
Palindrome number:
1. Start
2. Declare necessary variables
3. Input num
4. Copy the value of num to temp
5. While num!=0
div=num%10, rev=rev*10+div, num=num/10
6. End loop
7. if rev equals temp, print “The number is a Palindrome.”
Else, print “The number is not a Palindrome”
8. Stop
Magic Number:
1. Start
2. Declare necessary variables, initialize sum=100
3. Input num
4. While sum>=10
Initialize sum=0
While num!=0
Sum=sum+num%10
Num=num/10
End loop
Assign num=sum
End loop
5. If(sum==1), print “It is a Magic Number.”
Else, print “It is not a Magic Number.”
6. Stop
Prime and Armstrong:
1. Start
2. Declare the static method voidcheckPrime()
3. Declare necessary variables
4. Input num
5. For i 2 to num
6. if num%i==0, flag=1
7. End loop
8. if flag==1, print “It is a composite number.”
Else, print “It is a Prime number.”
9. Declare the static method voidcheckArmstrong()
10. Declare necessary variables
11. Input num
12. Assign the value of num to temp
13. While(num!=0)
14. Rem=num%10
15. Num=num/10
16. Sum=sum+rem*rem*rem
17. End loop
18. If sum==temp, print “It is an Armstrong number”
19. Else, print “It is not an Armstrong number”
20. Declare main method and call the above static
methods
21. Stop
Shapes program:
1. Start
2. Declare static method void Area, with int radius as
an argument
3. area=3.14*radius*radius
4. Print area
5. Declare static method int Rectangle, with int length
and int breadth as arguments
6. area=length*breadth
7. Return the value of area
8. Declare static method int Square, with no arguments
9. Declare necessary variables
10. Input the value of side
11. Perimeter = 4*a
12. Return the value of perimeter
13. Declare a main method
14. Input r, and call the static method Area(r)
15. Input l and b, and print the returned value after
passing it as an argument
16. Print the returned value of the perimeter of the
square
17. Stop
Currency Conversion:
1. Start
2. Declare static method double RstoDol, with double x
as an argument
3. Declare necessary variables
4. Convert=x/84.0
5. Return convert
6. Declare static method void DinartoRs, with no
argument
7. Declare necessary variables
8. Input d
9. Convert=d*273
10. Print convert
11. Declare static method int RstoYen, with no
argument
12. Declare necessary variables
13. Input r
14. Convert=r/0.56
15. Return convert
16. Declare main method
17. Input r
18. Print returned value after calling method
RstoDol(r)
19. Call static method DinartoRs()
20. Print returned value after calling method
RstoYen()
21. Stop