Every programmer starts somewhere. These exercises won’t feel exciting at first — they’re not meant to. They’re meant to wire your brain to think in steps, conditions, and loops. Once these feel natural, everything else gets easier.
Work through them in order. Use any language you like. The goal isn’t to memorize — it’s to struggle, figure it out, and move on.
1. Basic Input & Output
The foundation. Get comfortable reading values in and printing them out.
- WAP to print “Hello World”.
- WAP to take a user’s name as input and greet them:
Hello, Vishnu! - WAP to take two integers and print their sum, difference, product, quotient, and remainder.
- WAP to do the same with decimal (float) numbers.
- WAP to find the area of a rectangle given length and width.
- WAP to find the area of a triangle given base and height.
- WAP to find the area and circumference of a circle given the radius.
- WAP to convert Fahrenheit → Celsius and Celsius → Fahrenheit.
- WAP to convert millimeters → centimeters and back.
- WAP to convert degrees → radians using
radians = degrees × π / 180. - WAP to print the ASCII value of a character entered by the user.
- WAP to swap two numbers using a third variable.
- WAP to swap two numbers without using a third variable.
- WAP to calculate the average of three numbers.
- WAP to illustrate type conversion — convert an integer to a float and print both.
- WAP to find the simple interest given principal, rate, and time.
- WAP to find the compound interest given principal, rate, time, and number of times compounded per year.
2. Conditionals — if-else, switch, Operators
Learning to make decisions in code.
- WAP to find the greater of two numbers.
- WAP to find the greatest of three numbers using nested
if. - WAP to find the greatest of three numbers using logical operators.
- WAP to check if a number is positive, negative, or zero.
- WAP to check if a number is odd or even.
- WAP to check if a year is a leap year.
- WAP to check if a number is prime.
- WAP to check if a number is perfect (sum of proper divisors equals the number — e.g. 6 = 1+2+3).
- WAP to check if a number is divisible by 5.
- WAP to check if a character is an alphabet, digit, or special character.
- WAP to check if a character is a vowel or consonant.
- WAP to check if a character is uppercase or lowercase.
- WAP to take cost price and selling price and determine profit or loss.
- WAP to find the roots of a quadratic equation (handle real and complex roots).
- WAP to find the LCM and HCF of two numbers.
- WAP to build a basic calculator using a
switchstatement (add, subtract, multiply, divide).
Challenge: Redo every
if-elseproblem above using the ternary operator? :.
3. Loops
Repetition is the heart of programming.
- WAP to print numbers from 1 to N using
for,while, anddo-while. - WAP to print numbers from N to 1 (countdown).
- WAP to print all even numbers between two numbers entered by the user.
- WAP to print all odd numbers between two numbers entered by the user.
- WAP to print the multiplication table of a number entered by the user.
- WAP to find the factorial of a number using a loop.
- WAP to find the sum of digits of a number (e.g. 1234 → 10).
- WAP to count the number of digits in a number.
- WAP to reverse a number (e.g. 1234 → 4321).
- WAP to check if a number is a Palindrome (reads same forwards and backwards — e.g. 121).
- WAP to check if a number is an Armstrong number (e.g. 153 = 1³ + 5³ + 3³).
- WAP to print all Armstrong numbers between 1 and 1000.
- WAP to print the Fibonacci sequence up to N terms.
- WAP to find the sum of the series: 1 + 1/2 + 1/3 + … + 1/N.
- WAP to find the sum of the series: 1² + 2² + 3² + … + N².
- WAP to find the sum of the series: 1 + 2 + 3 + … + N (without using the formula, just a loop).
- WAP to print the prime numbers between 1 and 100.
4. Patterns
Pattern problems teach you to think in rows and columns — a core loop skill.
Left-aligned star triangle (n=4):
*
* *
* * *
* * * *
Inverted left-aligned triangle (n=4):
* * * *
* * *
* *
*
Number pattern (n=4):
1
2 2
3 3 3
4 4 4 4
Incremental number pattern (n=4):
1
1 2
1 2 3
1 2 3 4
Centered pyramid (n=4):
*
* * *
* * * * *
* * * * * * *
Inverted centered pyramid (n=4):
* * * * * * *
* * * * *
* * *
*
Diamond pattern (n=4):
*
* * *
* * * * *
* * * * * * *
* * * * *
* * *
*
Hollow square (n=5):
* * * * *
* *
* *
* *
* * * * *
Multiplication table grid (n=10):
0
0 1
0 2 4
0 3 6 9
0 4 8 12 16
...
Floyd’s Triangle (n=4):
1
2 3
4 5 6
7 8 9 10
Pascal’s Triangle (n=5):
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
5. Strings
String manipulation is in every job interview, every codebase.
- WAP to find the length of a string without using built-in functions.
- WAP to reverse a string (e.g.
"hello"→"olleh"). - WAP to check if a string is a palindrome (e.g.
"madam","racecar"). - WAP to count the vowels and consonants in a string.
- WAP to count the words in a sentence.
- WAP to convert a string to uppercase without using built-in functions.
- WAP to convert a string to lowercase without using built-in functions.
- WAP to count occurrences of a specific character in a string.
- WAP to remove all spaces from a string.
- WAP to replace all occurrences of a character with another character.
- WAP to check if two strings are anagrams (e.g.
"listen"and"silent"). - WAP to check if a string contains only digits.
- WAP to check if a string contains only alphabets.
- WAP to find the first non-repeating character in a string (e.g.
"aabbcde"→'c'). - WAP to find the most frequently occurring character in a string.
- WAP to remove duplicate characters from a string.
- WAP to compress a string using counts (e.g.
"aaabbc"→"a3b2c1").
6. Functions & Recursion
Functions break problems into pieces. Recursion teaches you to think about base cases.
- WAP using a function to check if a number is prime.
- WAP using a function to find the factorial of a number.
- WAP using a recursive function to find the factorial of a number.
- WAP using a recursive function to find the sum of natural numbers up to N.
- WAP using recursion to compute the Nth Fibonacci number.
- WAP using recursion to reverse a string.
- WAP using recursion to check if a string is a palindrome.
- WAP using recursion to find the power of a number:
x^n. - WAP using recursion to implement binary search.
- WAP using recursion to solve the Tower of Hanoi for N disks.
Tip: For every recursive function, write the same function iteratively first. Then rewrite it with recursion. Comparing both builds real understanding.
7. Arrays
Arrays are everywhere. Master these and data structures become approachable.
- WAP to print all elements of an array.
- WAP to find the sum and average of all array elements.
- WAP to find the largest and smallest elements in an array.
- WAP to find the second largest element.
- WAP to reverse an array without using built-in functions.
- WAP to check if an array is sorted (ascending order).
- WAP to remove duplicates from an array.
- WAP to count occurrences of each element in an array.
- WAP to rotate an array left by K positions.
- WAP to merge two sorted arrays into a single sorted array.
- WAP to find all pairs in an array that add up to a given sum.
- WAP to search for an element using Linear Search.
- WAP to search for an element using Binary Search (array must be sorted).
- WAP to sort an array using Bubble Sort.
- WAP to sort an array using Selection Sort.
- WAP to sort an array using Insertion Sort.
- WAP to sort an array using Merge Sort.
- WAP to sort an array using Quick Sort.
- WAP to work with a 2D array — print row-wise and column-wise.
- WAP to find the transpose of a matrix.
- WAP to multiply two matrices.
8. Math & Number Theory
These problems come up in competitive programming and technical interviews.
- WAP to find all factors of a number.
- WAP to find the GCD (Greatest Common Divisor) of two numbers using Euclidean algorithm.
- WAP to find the LCM using the GCD.
- WAP to check if a number is a perfect square.
- WAP to find the square root of a number without using
sqrt(). - WAP to generate a prime sieve (Sieve of Eratosthenes) up to N.
- WAP to convert a decimal number to binary (without built-ins).
- WAP to convert binary to decimal.
- WAP to convert decimal to octal and octal to decimal.
- WAP to convert decimal to hexadecimal and back.
- WAP to check if a number is a Fibonacci number.
- WAP to find the digital root of a number (repeatedly sum digits until single digit).
- WAP to check if a number is a Kaprekar number (e.g. 45 → 45² = 2025, 20+25=45).
- WAP to check if a number is a Happy number (repeatedly sum squares of digits; happy if reaches 1).
9. Object-Oriented Programming (OOP) Basics
Once you’re comfortable with functions and arrays, start thinking in objects.
- Create a
Personclass with name, age, and a methodgreet()that prints “Hi, I’m [name] and I’m [age] years old.” - Create a
Calculatorclass with methods for add, subtract, multiply, and divide. - Create a
Rectangleclass with methods for area and perimeter. - Create a
Circleclass with methods for area and circumference. - Create a
BankAccountclass with methods to deposit, withdraw, and check balance. Prevent withdrawal if balance is insufficient. - Create a
Studentclass with name, marks array, and methods to calculate total, average, and grade. - Demonstrate inheritance — create an
Animalbase class with aspeak()method, then createDogandCatsubclasses that override it. - Demonstrate encapsulation — use private fields and public getters/setters.
- Demonstrate polymorphism — use method overloading or overriding.
Where to Go Next
These exercises cover the essentials. Once they feel comfortable:
- Data structures — linked lists, stacks, queues, hash maps, trees
- LeetCode Easy problems — start with the top 50, focus on arrays and strings
- Build something — a calculator, a to-do list, a number guessing game
Need a quick reference while you code? See the programming language cheatsheets: Git Cheat Sheet | Linux & Bash Cheat Sheet
Happy coding. The struggle is the point.