0% found this document useful (0 votes)
9 views2 pages

C Exercises Medium To Hard

Uploaded by

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

C Exercises Medium To Hard

Uploaded by

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

C Exercises from Medium to Hard

Medium Level Exercises:


1. Calculate the factorial of an integer
Write a program to calculate the factorial of a positive integer n (using loops
and recursion).

2. Prime number check


Write a program to check if a number is prime.

3. Print Fibonacci sequence


Write a program to print the Fibonacci sequence up to the n-th term (can be done
with recursion or loops).

4. Reverse a string
Write a program to input a string and reverse it.

5. Palindrome string check


Write a program to check if a string is a palindrome.

6. Sum of digits of a number


Write a program to input a positive integer and calculate the sum of its digits.

7. Greatest common divisor (GCD)


Write a program to find the greatest common divisor of two positive integers
using the recursive Euclidean method.

8. Sum of a series
Write a program to calculate the sum of numbers from 1 to n using loops or
recursion.

Advanced Level Exercises:


1. Print a number triangle
Write a program to print a number triangle like this:
1
1 2
1 2 3
1 2 3 4

2. Convert decimal to binary


Write a program to convert a decimal number to binary.

3. Bubble Sort array


Write a program to input an array and sort it in ascending order using Bubble
Sort algorithm.

4. Find the second largest element in an array


Write a program to find the second largest element in an array of integers.

5. Numerical integration using trapezoidal rule


Write a program to numerically integrate a function using the trapezoidal rule.

6. Binary search
Write a program to search for an element in a sorted array using binary search.

7. Tower of Hanoi
Write a program to solve the Tower of Hanoi problem using recursion, moving all
disks from peg A to peg C under given constraints.

8. Fibonacci series using dynamic programming


Write a program to calculate Fibonacci numbers using dynamic programming for
efficiency.

Hard Level Exercises:


1. Dynamic memory management
Write a program to create a dynamic array using pointers and the malloc library,
allowing addition, deletion of elements, and displaying the array.

2. Calculate large Fibonacci numbers


Write a program to calculate large Fibonacci numbers without direct recursion
(use matrix exponentiation or other optimizations for efficiency).

3. Quick Sort algorithm


Write a program to sort an array using the Quick Sort algorithm.

4. Singly Linked List implementation


Write a program to implement a singly linked list with operations: insert,
delete, search, and display the list.

5. Count prime numbers in a range


Write a program to count all prime numbers in a range [a, b] using the Sieve of
Eratosthenes.

6. Spiral matrix printing


Write a program to print elements of a matrix in a spiral order starting from
the top-left corner and moving clockwise.

7. Maze pathfinding
Write a program to find a path through a maze represented as a 2D matrix using
recursive backtracking.

8. Binary Search Tree implementation


Write a program to implement a Binary Search Tree with operations: insert,
delete, search, and inorder traversal.

You might also like