0% found this document useful (0 votes)
3 views

Algorithms

The document outlines various algorithms for different tasks including checking voting eligibility, assigning grades based on marks, performing arithmetic operations, evaluating buzz numbers, determining prime numbers, printing patterns, checking for palindromes, identifying magic numbers, and calculating areas of shapes. It also includes methods for currency conversion and checking for Armstrong numbers. Each algorithm is structured with a clear start, input, processing steps, and output instructions.

Uploaded by

brickyshawn
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Algorithms

The document outlines various algorithms for different tasks including checking voting eligibility, assigning grades based on marks, performing arithmetic operations, evaluating buzz numbers, determining prime numbers, printing patterns, checking for palindromes, identifying magic numbers, and calculating areas of shapes. It also includes methods for currency conversion and checking for Armstrong numbers. Each algorithm is structured with a clear start, input, processing steps, and output instructions.

Uploaded by

brickyshawn
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Algorithms:

Checking Eligibility to Vote:

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

Assigning Grade based on Marks:

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

Arithmetic Operations Calculator:

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

Buzz Number Evaluator and HCF & LCM Calculation:

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

Determining whether a number is Prime

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

Printing the given number pattern:

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 li-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 li-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

You might also like