Sample Programming Questions
Sample Programming Questions
Looping:
1. Print Multiplication Table
Write a program that takes an integer as input and prints its multiplication table up
to 10 using a for loop.
2. Sum of First N Natural Numbers
Write a program that takes an integer N and calculates the sum of the first N natural
numbers using a while loop.
3. Count Digits in a Number
Write a program that takes an integer as input and counts the number of digits using
a while loop.
Array:
1. Sum of Array Elements
Write a program to calculate the sum of all elements in an integer array.
Function:
1. Calculate Factorial
Write a function to calculate the factorial of a number using recursion.
2. Check Prime Number
Write a function to check whether a given number is prime.
3. Find GCD (Greatest Common Divisor)
Write a function to find the GCD of two numbers using the Euclidean algorithm.
4. Reverse a Number
Write a function to reverse the digits of a given number.
5. Fibonacci Series
Write a function to print the Fibonacci series up to a given number of terms.
6. Check Palindrome
Write a function to check whether a given string or number is a palindrome.
7. Power Calculation
Write a function to calculate the power of a number (base^exponent) using
recursion.
8. Sort an Array
Write a function to sort an array using the selection sort algorithm.
9. Count Vowels in a String
Write a function to count the number of vowels in a given string.
Recursion:
1. Factorial of a Number
Write a recursive function to calculate the factorial of a given number.
2. Fibonacci Series
Write a recursive function to print the Fibonacci series up to a given term.
3. Sum of Natural Numbers
Write a recursive function to calculate the sum of the first n natural numbers.
4. Reverse a Number
Write a recursive function to reverse the digits of a given number.
5. Power of a Number
Write a recursive function to calculate base^exponent.
6. Greatest Common Divisor (GCD)
Write a recursive function to find the GCD of two numbers using the Euclidean
algorithm.
7. Check Palindrome (String)
Write a recursive function to check if a string is a palindrome.
8. Sum of Digits
Write a recursive function to calculate the sum of the digits of a number.
Pointer:
1. Swap Two Numbers
Write a function to swap two numbers using pointers.