3 views
26 Jan 2026
Find all prime numbers between 1 and N efficiently.
Real Life: Used in cryptography and security.
Step-by-Step Logic:
1. Create array marking all numbers as prime initially
2. Start from 2 (firs...
3 views
26 Jan 2026
Convert decimal number to binary (base 2) representation.
Real Life: How computers store all data internally.
Step-by-Step Logic:
1. Take decimal number
2. Divide by 2 repeatedly
3. Store remai...
5 views
26 Jan 2026
Print diamond shape using stars.
Real Life: Making decorative patterns.
Step-by-Step Logic:
1. Divide into two parts: upper and lower
2. Upper part: spaces decrease, stars increase
3. Lower par...
5 views
26 Jan 2026
Number equals sum of cubes of its digits. Example: 153 = 1³+5³+3³
Real Life: Special numbers in mathematics.
Step-by-Step Logic:
1. Take original number and save it
2. Extract each digit one...
5 views
26 Jan 2026
Find largest number that divides both numbers completely.
Example: GCD of 12 and 18 is 6
Real Life: Used when simplifying fractions.
Step-by-Step Logic:
1. Take two numbers
2. Find smaller of t...
5 views
26 Jan 2026
Print series where each number is sum of previous two: 0,1,1,2,3,5,8...
Real Life: This pattern appears in nature like flower petals, pine cones.
Step-by-Step Logic:
1. Start with first two numbe...
4 views
26 Jan 2026
Check if number is prime (only divisible by 1 and itself).
Real Life: Like checking if you can divide chocolates equally in groups.
Step-by-Step Logic:
1. Take number to check
2. Try dividing by...
5 views
26 Jan 2026
Find factorial of N. Example: 5! = 5×4×3×2×1 = 120
Real Life: Used in probability and permutation calculations.
Step-by-Step Logic:
1. Take number N
2. Start result = 1
3. Multiply result w...
3 views
26 Jan 2026
Print multiplication table of any number (like 5 × 1 = 5, 5 × 2 = 10...)
Real Life: Like the multiplication tables you learn in school.
Step-by-Step Logic:
1. Take number for which you want tab...
4 views
26 Jan 2026
Check if given year is leap year or not.
Real Life: Like February having 29 days in some years.
Step-by-Step Logic:
1. Take year as input
2. Leap year if divisible by 4
3. But NOT leap if divisib...
4 views
26 Jan 2026
Make calculator that can add, subtract, multiply or divide.
Real Life: Like calculator on your phone.
Step-by-Step Logic:
1. Take two numbers
2. Take operation choice (+, -, *, /)
3. Use switch t...
5 views
26 Jan 2026
If N = 5, find sum 1+2+3+4+5 = 15
Real Life: Like adding page numbers from page 1 to page N.
Step-by-Step Logic:
1. Take value of N
2. Start sum = 0
3. Add numbers from 1 to N one by one
4. Prin...
3 views
26 Jan 2026
You have three numbers. Find which one is largest. Real Life: Like finding tallest person among three friends.
Step-by-Step Logic:
1. Take three numbers
2. First compare first two numbers
3. Then ...
2 views
26 Jan 2026
A student needs 40 marks to pass. Check if student passed or failed.
Step-by-Step Logic:
1. Take student's marks
2. Compare marks with passing marks (40)
3. If marks >= 40, student passed
4. O...