0% found this document useful (0 votes)
11 views8 pages

Practice Problem

The document outlines a series of programming tasks categorized by difficulty levels, focusing on concepts such as if-else statements, loops, and functions. It includes beginner and intermediate level exercises like determining odd/even numbers, calculating factorials, and printing patterns. Additionally, it features function-based challenges like checking prime numbers and calculating grades.

Uploaded by

msrafin2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views8 pages

Practice Problem

The document outlines a series of programming tasks categorized by difficulty levels, focusing on concepts such as if-else statements, loops, and functions. It includes beginner and intermediate level exercises like determining odd/even numbers, calculating factorials, and printing patterns. Additionally, it features function-based challenges like checking prime numbers and calculating grades.

Uploaded by

msrafin2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

if-else

Beginner Level

1. Odd or Even

o Input: An integer.

o Task: Determine if the number is odd or even using if-else.

2. Maximum of Three Numbers

o Input: Three integers.

o Task: Use conditional statements to print the largest number.

3. Simple Grading System

o Input: A student's score (0–100).

o Task: Print the grade based on score (e.g., A: 90+, B: 80–89, etc.).

4. Leap Year Checker

o Input: A year.

o Task: Check if the year is a leap year using conditions.

5. Character Type Identifier

o Input: A single character.

o Task: Determine if it's a letter, digit, or special character using ASCII values
and conditions.

Intermediate Level

6. Triangle Type Checker

o Input: Three side lengths.

o Task: Determine if it is a valid triangle. If valid, say if it is equilateral,


isosceles, or scalene.

7. Number Sign Checker

o Input: A number.
o Task: Print whether it's positive, negative, or zero.

8. Simple Calculator (using switch)

o Input: Two numbers and an operator (+, -, *, /).

o Task: Perform the operation using a switch statement.

9. Day of the Week

o Input: An integer (1 to 7).

o Task: Use switch to print the corresponding day (1 = Monday, etc.).

10. Vowel or Consonant

• Input: A character.

• Task: Determine if the character is a vowel or consonant.

Loop
Beginner Level

1. Print Numbers from 1 to N


o Input: An integer N.

o Task: Use a for or while loop to print numbers from 1 to N.

2. Sum of First N Natural Numbers

o Input: An integer N.

o Task: Calculate and print the sum using a loop.

3. Multiplication Table

o Input: An integer n.
o Task: Print the multiplication table of n up to 10.

4. Factorial of a Number

o Input: An integer n.

o Task: Calculate n! using a loop.

5. Count Digits in a Number


o Input: An integer n.
o Task: Use a loop to count the number of digits.

Intermediate Level

6. Reverse a Number

o Input: An integer.

o Task: Use a loop to reverse the digits of the number.

7. Palindrome Number

o Input: An integer.

o Task: Check if the number reads the same backward using loops.

8. Sum of Digits

o Input: An integer.
o Task: Calculate the sum of all its digits using a loop.

9. Prime Number Checker

o Input: An integer n.

o Task: Use a loop to determine whether n is a prime number.

10. Pattern Printing (Stars)

• Input: An integer n.

🌟 Nested Loop Practice Problems (C++)

1. Square Pattern of Stars


• Input: n (number of rows and columns)

• Task: Print a square of stars using nested for loops.

• Example (n = 4):

markdown

CopyEdit
****

****
****
****

2. Right-Angled Triangle of Stars

• Input: n (number of rows)

• Task: Print a right-angled triangle.


• Example (n = 5):

markdown

CopyEdit

**

***

****

*****
3. Inverted Right-Angled Triangle

• Input: n

• Task: Print an inverted right triangle.

• Example (n = 4):

markdown

CopyEdit

****
***

**

4. Multiplication Table Grid

• Input: n (up to which number)

• Task: Print a multiplication table from 1 to n.

• Example (n = 3):
CopyEdit
123

246

369

5. Number Pyramid
• Input: n

• Task: Print a number triangle where each row prints numbers from 1 to that row number.

• Example (n = 4):

CopyEdit

12

123

1234
6. Pascal’s Triangle

• Input: n (number of rows)

• Task: Print the first n rows of Pascal’s Triangle using nested loops.

7. Hollow Square Pattern

• Input: n

• Task: Print a square of *, but only borders filled.

• Example (n = 5):
markdown

CopyEdit

*****

* *

* *

* *

*****
8. Diamond Pattern
• Input: n (odd number, number of total rows)

• Task: Print a diamond shape using stars. This uses nested loops and some math with
spaces.

• Example (n = 5):

markdown

CopyEdit

*
***

*****
***

9. Checkerboard Pattern (Alternating 1 and 0)

• Input: n (rows and columns)

• Task: Print alternating 1s and 0s like a checkerboard.


• Example (n = 4):

CopyEdit

1010

0101

1010

0101

10. Matrix Input & Transpose


• Task: Let the user input a 2D matrix, then use nested loops to compute and print its
transpose.

1. Sum of Two Numbers


• Task: Write a function int add(int a, int b) that returns the sum of two numbers.

• Practice Focus: Function parameters and return values.

2. Check Prime Number


• Task: Write a function bool isPrime(int n) that returns true if the number is prime, false
otherwise.

• Use Case: Can be reused in other problems like printing all primes from 1 to N.

3. Factorial Using Function

• Task: Create a function long long factorial(int n) that returns the factorial of a number.

4. Greatest Common Divisor (GCD)

• Task: Write a function int gcd(int a, int b) to compute the GCD using Euclid's algorithm.
5. Swap Two Numbers

• Task: Write a function void swap(int &a, int &b) that swaps two integers using reference
variables.

6. Find Maximum in Array

• Task: Write a function int findMax(int arr[], int size) that returns the maximum element in
an array.

• Note: Practice array handling with functions.

7. Check Palindrome (Integer or String)

• Task: Create a function bool isPalindrome(int num) or bool isPalindrome(string str).

8. Fibonacci Series (Nth Term)

• Task: Write a function int fibonacci(int n) that returns the nth Fibonacci number.

• Stretch: Use recursion and discuss performance.


9. Menu-Driven Calculator Using Functions

• Task: Write functions for add, subtract, multiply, divide, and call them from a main menu.

10. Grade Calculator

• Task: Write a function char calculateGrade(int marks) that returns a grade based on mark
ranges.

• Bonus: Add another function that averages marks from multiple subjects and then calls
calculateGrade().

Function + Loop Combo Examples

These encourage function decomposition with iteration:


11. Print All Prime Numbers from 1 to N

• Use a loop in main() and call isPrime() for each number.

12. Check Armstrong Number

• Function: bool isArmstrong(int n)


• Bonus: Loop through a range to find all Armstrong numbers.

13. Pattern Generator Function

• Function: void printTriangle(int rows) that prints a pattern using nested loops.

You might also like