Suggestions logoSuggestions

Problems

Practice problems and exercises.

1. Largest and smallest using pointers

Write a program that takes N numbers, stores them in an array, and prints the largest and smallest using pointers.

2. Armstrong numbers 1–500

Find and print all Armstrong numbers between 1 and 500.

3. Sum of positives and negatives from file

Open a file of integers and print separate sums of positives and negatives.

4. Factorial from 1 to n

Take n and print factorials for 1 to n using a for loop.

5. Prime check for N test cases

For each of N inputs, check if the number is prime (loop based).

6. Swap without third variable

Swap two numbers using arithmetic operators only.

7. Sum of primes 1–50

Print the sum of all prime numbers between 1 and 50.

8. Write 1–10 to file and sum

Create output.txt, write 1–10, then reopen and compute their sum.

9. Palindrome string (no string.h)

Read a string and print whether it is a palindrome without using string library functions.

10. Merge two arrays

Merge arrays of size m and n into a third array and print it.

11. Hollow square pattern

Draw a hollow square of side length n using '*'.

12. AP terms (a=5, d=3)

Generate the first 20 terms of the AP where a=5 and d=3.

13. Perfect numbers 1–500

Display all perfect numbers between 1 and 500.

14. Count vowels

Take a string and count the number of vowels.

15. Stats from mixed-number file

Read integers/floats/doubles until EOF; print count, sum, min, max, average.

16. Even/odd sum using conditional operator

Check whether the sum of two integers is even or odd using ?: .

17. Count positives, negatives, zeros

Read an integer array; count positives, negatives, and zeros.

18. Recursive sum of digits

Compute the sum of digits of an integer using recursion.

19. Highest mark and average from file

Read Name–Marks pairs; print the student with highest mark and the average mark.

20. Reverse array in place

Reverse an integer array in place without a second array.

21. Rotate array right by one

Rotate elements of an array to the right by one position.

22. Multiplication table

Print the multiplication table of a number using a for loop.

23. Recursive GCD

Compute the GCD of two integers using recursion.

24. Sign of product using conditional operator

Read three integers; determine if their product is positive, negative, or zero using ?: .

25. Divisibility using conditional operator

Check whether the first number is divisible by the second using ?: .

26. Binary of integer (no arrays/strings)

Print the binary representation of an integer using loops and division/modulus only.

27. Count uppercase and lowercase

Read a string and count uppercase and lowercase letters separately.

28. Reverse integer using recursion

Find the reverse of an integer using recursion.

29. Diamond pattern

Print a diamond pattern for input size 5.

30. Remove duplicates from array

Read an array of integers; remove duplicate values and print the updated array.

On this page