Page 1 of 19
Practice Problems on Loop
1. Compute Power of a Number
Write a program that takes two numbers x and n as input and computes without using
the pow() function.
2. Find All Divisors
Write a program that finds and prints all divisors of a given integer n.
3. Compute Factorial
Write a program to calculate the factorial (n!) of a given number using a loop.
4. Find Maximum and Minimum from a List
Write a program that takes multiple integers as input and determines the largest and
smallest numbers among them.
5. Find Second Maximum from a list
Write a program that takes multiple integers as input and determines the second maximum
number among them.
6. Count the Number of Digits in an Integer
Write a program that takes an integer and counts the number of digits it contains.
7. Digit Sum and Product
Write a program that calculates the sum and product of the digits of a given number.
8. Find the Sum of Even and Odd Digits Separately
Write a program that separates even and odd digits of a number and prints their respective
sums.
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 2 of 19
9. Reverse Digits of an Integer
Write a program that reverses the digits of a given integer n.
Example: If n = 1025, output should be 5201.
10.Check if a Number is Palindrome
A number is a palindrome if it reads the same forward and backward.
Example: 121 is a palindrome, but 123 is not.
11.Find Perfect Numbers
A perfect number is a number whose divisors' sum (excluding itself) equals the number.
Example of perfect numbers: 6, 28, 496, 8128.
6→1+2+3=6
Write a program to check if a number is perfect or not.
12.Check Armstrong Number
A number is Armstrong if the sum of its digits raised to the power of the number of digits is
equal to the number itself.
Example: 153, 371,1634, 8208, 9474, 54748, 93084
153 = 1³ + 5³ + 3³ = 153
Write a program to check if a number is Armstrong or not.
13.Check Prime Number
Write a program to determine if n is prime or not.
Example: Input: 29 → Output: Prime
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 3 of 19
14.Print Prime Numbers in a Range
Write a program that prints all prime numbers from 1 to n.
15.Sum of Prime Numbers
Write a program that computes the sum of all prime numbers from 1 to n.
16.Count the Number of Prime Digits in a Number
Example: 25739 → Prime Digits: 2, 5, 7, 3 → Count: 4.
17.Find GCD (Greatest Common Divisor)
Given two numbers, find their GCD using loops.
Example: Input: 12 18 → Output: 6
18.Find LCM (Least Common Multiple)
Write a program to compute LCM of two numbers using the GCD formula and also by LCM
formula.
19.Check Co-Prime Numbers
Two numbers are co-prime if their GCD is 1.
Write a program to check if two numbers are co-prime or not.
20.Find Sum of Digits Until a Single Digit
Given a number n, keep adding its digits until you get a single-digit number.
Example: Input: 9875 → Output: 2
(9+8+7+5=29 → 2+9=11 → 1+1=2)
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 4 of 19
21.Compute Different Number Series up to n Terms
Write a program that prints the sum of the following series up to n terms:
22.Fibonacci Series
The Fibonacci series is a sequence of numbers in which each number is the sum of the two
preceding ones, starting from 0 and 1.
First 15 Fibonacci Numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377...
Write a program to print the first n Fibonacci numbers using loops.
23.Permutation (nPr) and Combination (nCr) Calculation
Permutation (nPr):
The number of ways to arrange r items from a set of n objects where order matters.
Formula:
Simplified Form:
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 5 of 19
Combination (nCr):
The number of ways to choose r items from a set of n objects where order does not
matter.
Formula:
Simplified Form:
Given two numbers n and r, compute nPr and nCr.
Number System Conversions
1. Convert Decimal to Binary
Convert a decimal (non-negative) integer to binary without using built-in functions.
2. Convert Decimal to Binary (Two’s Complement Form)
Convert a negative decimal integer to binary using 2’s complement representation.
3. Validate and Convert Binary to Decimal
Given a binary number, first check if it's valid and then convert it to decimal.
4. Convert Decimal to Hexadecimal Using a Loop
Write a program that converts a decimal number to hexadecimal manually.
5. Convert Binary to Hexadecimal Using a Loop
Convert a binary number to hexadecimal manually.
6. Convert Hexadecimal to Decimal
Take an input in hexadecimal form and print its decimal equivalent.
7. Convert Octal to Decimal and Binary
Convert octal numbers to decimal and binary.
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 6 of 19
Some Problems On patterns
You are given a positive integer n as an input , you have to make the following
patterns according to the input n.
1. For n = 5, 2. For n = 5 3. For n =5 4. For n= 5
* * ***** *****
** ** **** ****
*** *** *** ***
**** **** ** **
***** ***** * *
5. For n=5 6. For n=5 7. For n=5 8. For n=5
***** *
***** ***** ** ** **
***
* * ** * * * *
****
* * * * * ** **
*****
* * * ** ***** ****
***** ***** ***
**
*
9. For n=5 10.For n =5 11.For n =5 12.For n =5
*
** ***** ***** * *
*** **** **** * *
**** *** *** * *
***** ** ** * *
**** * * *
*** ** ** * *
** *** *** * *
* **** **** * *
***** ***** * *
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 7 of 19
13. For n=5 14. For n=5 15. For n=5 16. For n=5
1 1 1 1
12 22 21 212
123 333 321 32123
1234 4444 4321 4321234
12345 55555 54321 543212345
17. For n=5 18. For n=5 19. For n=5 20. For n=5
1 1 5 5 1
121 2 2 4 4 2 2
12321 3 3 3 3 3 3
1234321 4 4 2 2 4 4
123454321 5 5 1 5 5
4 4
3 3
2 2
1
21. For n=5 22. For n=5 23. For n=5 24. For n=5
1 1 1 2 1
212 2 3 3 4 2 3
32123 4 5 5 6 4 5
4321234 6 7 7 8 6 7
543212345 8 9 9 8
123454321
1234321
12321
121
1
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 8 of 19
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 9 of 19
Online and Offline Problems of CSE Lab of BUET On Loop
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 10 of 19
Problem -3
Problem – 4
Problem – 5
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 11 of 19
Problem – 6
Problem – 7
Problem – 8
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 12 of 19
Problem – 9
Problem – 10
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 13 of 19
Problem – 11
Problem – 12
Problem – 13
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 14 of 19
Problem – 14
Problem – 15
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 15 of 19
Problem – 16
Problem – 17
Problem – 18
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 16 of 19
Problem – 19:
Problem – 20:
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 17 of 19
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 18 of 19
Problem – 21:
Problem – 22:
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)
Page 19 of 19
Practice the Term Final Questions by Yourself.
Source of the problems of this Sheet-
Self-created problems
Lab Assessments of CSE course of BUET
Taken help from AI
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996(Whatsapp)