0% found this document useful (0 votes)
8 views5 pages

Essential Algorithms with Explanations

The document outlines various algorithms for basic mathematical operations and checks, including addition, finding the largest number, checking even/odd, calculating factorials, swapping numbers, checking for prime numbers, generating Fibonacci series, checking leap years, reversing numbers, and checking for palindromes. Each algorithm is presented with a step-by-step process and a brief explanation of its function. The document serves as a guide for implementing these algorithms in programming.

Uploaded by

haramyawr3434
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Essential Algorithms with Explanations

The document outlines various algorithms for basic mathematical operations and checks, including addition, finding the largest number, checking even/odd, calculating factorials, swapping numbers, checking for prime numbers, generating Fibonacci series, checking leap years, reversing numbers, and checking for palindromes. Each algorithm is presented with a step-by-step process and a brief explanation of its function. The document serves as a guide for implementing these algorithms in programming.

Uploaded by

haramyawr3434
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Algorithms with Explanations

1. Algorithm for Addition of Two Numbers:


Step 1: Start
Step 2: Input two numbers (A, B)
Step 3: Compute Sum = A + B
Step 4: Display Sum
Step 5: End

Explanation:
This algorithm takes two numbers as input, adds them, and displays the sum.

2. Algorithm for Finding the Largest of Three Numbers:


Step 1: Start
Step 2: Input three numbers (A, B, C)
Step 3: If A > B and A > C, then Largest = A
Step 4: Else if B > A and B > C, then Largest = B
Step 5: Else Largest = C
Step 6: Display Largest
Step 7: End

Explanation:
This algorithm checks conditions to determine the largest number among three inputs.

3. Algorithm for Checking Even or Odd Number:


Step 1: Start
Step 2: Input a number (N)
Step 3: If N % 2 == 0, then display "Even"
Step 4: Else display "Odd"
Step 5: End

Explanation:
This algorithm checks whether a number is even or odd using modulus (%).

4. Algorithm for Finding Factorial of a Number:


Step 1: Start
Step 2: Input a number (N)
Step 3: Initialize Fact = 1
Step 4: Repeat for i = 1 to N
- Fact = Fact * i
Step 5: Display Fact
Step 6: End

Explanation:
Factorial of N is the product of all numbers from 1 to N.

5. Algorithm for Swapping Two Numbers Without Using a Third Variable:


Step 1: Start
Step 2: Input two numbers (A, B)
Step 3: A = A + B
Step 4: B = A - B
Step 5: A = A - B
Step 6: Display A and B
Step 7: End

Explanation:
This swaps two numbers without a temporary variable.

6. Algorithm for Checking if a Number is Prime:


Step 1: Start
Step 2: Input a number (N)
Step 3: If N <= 1, display "Not Prime" and stop
Step 4: For i = 2 to N/2
- If N % i == 0, display "Not Prime" and stop
Step 5: Display "Prime"
Step 6: End

Explanation:
A prime number is only divisible by 1 and itself.

7. Algorithm for Fibonacci Series up to N Terms:


Step 1: Start
Step 2: Input N
Step 3: Initialize a = 0, b = 1
Step 4: Display a, b
Step 5: Repeat for i = 3 to N
- Next = a + b
- Display Next
- a = b, b = Next
Step 6: End

Explanation:
Fibonacci series starts with 0 and 1, each term is sum of previous two.

8. Algorithm for Checking Leap Year:


Step 1: Start
Step 2: Input year (Y)
Step 3: If (Y % 4 == 0 and Y % 100 != 0) or (Y % 400 == 0), display "Leap Year"
Step 4: Else display "Not a Leap Year"
Step 5: End

Explanation:
A Leap Year occurs every 4 years, except centuries not divisible by 400.

9. Algorithm for Reversing a Number:


Step 1: Start
Step 2: Input number (N)
Step 3: Initialize Reverse = 0
Step 4: While N > 0
- R = N % 10
- Reverse = Reverse * 10 + R
- N = N / 10
Step 5: Display Reverse
Step 6: End

Explanation:
Extracts digits and forms the reversed number.

10. Algorithm for Checking if a Number is Palindrome:


Step 1: Start
Step 2: Input number (N)
Step 3: Store original number in Temp
Step 4: Reverse the number using previous algorithm
Step 5: If Reverse == Temp, display "Palindrome"
Step 6: Else display "Not Palindrome"
Step 7: End

Explanation:
Palindrome numbers read the same forward and backward.

11. Algorithm for Finding the Remainder Using Modulus Operator:


Step 1: Start
Step 2: Input two numbers (A, B)
Step 3: Compute Remainder = A % B
Step 4: Display Remainder
Step 5: End

Explanation:
Finds remainder when one number is divided by another.

12. Algorithm for Checking Leap Year:


Step 1: Start
Step 2: Input year (Y)
Step 3: If (Y % 4 == 0 and Y % 100 != 0) or (Y % 400 == 0), display "Leap Year"
Step 4: Else display "Not a Leap Year"
Step 5: End

Explanation:
A Leap Year occurs every 4 years, except centuries not divisible by 400.

You might also like