Practice Question
Practice Question
Practice Question
1. Write a program that asks the user to enter a number and prints whether it is a prime
number or not using loops and conditionals.
2. Create a C++ program to print the sum of all odd numbers between 1 to 100 using loops
and conditionals.
3. Write a program that prompts the user to enter a number and then prints the multiplication
table for that number up to 10 using loops and conditionals.
4. Develop a program that asks the user to input a number and prints whether it is a
palindrome or not using loops and conditionals.
5. Write a C++ program to find the factorial of a number entered by the user. Use loops and
conditionals.
6. Create a program that prints the Fibonacci series up to a given number 'n' entered by the
user using loops and conditionals.
7. Write a C++ program to print the following pattern using loops and conditionals:
*
**
***
****
*****
8. Create a program that takes a number from the user and prints the reverse of that number
using loops and conditionals.
e.g
if your were given number 234
print 432
9. Write a C++ program to check whether a given year is a leap year or not using loops and
conditionals.
10. Write a C++ program to print the following pattern using loops and conditionals:
1
12
123
1234
12345
11. Write a C++ program to print the following pattern using loops and conditionals:
12345
1234
123
12
1
12. Given two sorted arrays nums1 and nums2 of size m and n respectively, calculate the
median of the two sorted arrays.
13. Given an array of integers nums and an integer target, Calculate indices of the two
numbers such that they add up to target.
14. Given an integer array nums sorted in non-decreasing order, remove the duplicates in-
place such that each unique element appears only once. The relative order of the elements
should be kept the same. Then tell the number of unique elements in nums.
15. Given an array nums of distinct integers, return all the possible permutations. You can
return the answer in any order.
Example 1:
Example 2:
Example 3:
Example 3: