Loop programming exercises and solutions in C

Loops in programming are used to perform repetitive tasks. If there is a statement which is to be repeated multiples times we use loop. There are generally three types of loops:

Here is a set of programming exercises based on loops to practice.
  1. Write a C program to print all natural numbers from 1 to n. - using while loop
  2. Write a C program to print all natural numbers in reverse (from n to 1). - using while loop
  3. Write a C program to print all alphabets from a to z. - using while loop
  4. Write a C program to print all even numbers between 1 to 100. - using while loop
  5. Write a C program to print all odd number between 1 to 100.
  6. Write a C program to print sum of all even numbers between 1 to n.
  7. Write a C program to print sum of all odd numbers between 1 to n.
  8. Write a C program to print table of any number.
  9. Write a C program to enter any number and calculate sum of all natural numbers between 1 to n.

  10. Write a C program to find first and last digit of any number.
  11. Write a C program to count number of digits in any number.
  12. Write a C program to calculate sum of digits of any number.
  13. Write a C program to calculate product of digits of any number.
  14. Write a C program to swap first and last digits of any number.
  15. Write a C program to find sum of first and last digit of any number.
  16. Write a C program to enter any number and print its reverse.
  17. Write a C program to enter any number and check whether the number is palindrome or not.
  18. Write a C program to find frequency of each digit in a given integer.

  19. Write a C program to enter any number and print it in words.
  20. Write a C program to print all ASCII character with their values.
  21. Write a C program to find power of any number using for loop.
  22. Write a C program to enter any number and print all factors of the number.
  23. Write a C program to enter any number and calculate its factorial.
  24. Write a C program to find HCF (GCD) of two numbers.
  25. Write a C program to find LCM of two numbers.

  26. Write a C program to check whether a number is Prime number or not.
  27. Write a C program to check whether a number is Armstrong number or not.
  28. Write a C program to check whether a number is Perfect number or not.
  29. Write a C program to check whether a number is Strong number or not.
  30. Write a C program to print all Prime numbers between 1 to n.
  31. Write a C program to print all Armstrong numbers between 1 to n.
  32. Write a C program to print all Perfect numbers between 1 to n.
  33. Write a C program to print all Strong numbers between 1 to n.
  34. Write a C program to enter any number and print its prime factors.
  35. Write a C program to find sum of all prime numbers between 1 to n.
  36. Write a C program to print Fibonacci series up to n terms.

  37. Write a C program to find one's complement of a binary number.
  38. Write a C program to find two's complement of a binary number.
  39. Write a C program to convert Binary to Octal number system.
  40. Write a C program to convert Binary to Decimal number system.
  41. Write a C program to convert Binary to Hexadecimal number system.
  42. Write a C program to convert Octal to Binary number system.
  43. Write a C program to convert Octal to Decimal number system.
  44. Write a C program to convert Octal to Hexadecimal number system.
  45. Write a C program to convert Decimal to Binary number system.
  46. Write a C program to convert Decimal to Octal number system.
  47. Write a C program to convert Decimal to Hexadecimal number system.
  48. Write a C program to convert Hexadecimal to Binary number system.
  49. Write a C program to convert Hexadecimal to Octal number system.
  50. Write a C program to convert Hexadecimal to Decimal number system.

  51. Write a C program to print Pascal triangle upto n rows.
  52. Star pattern programs - Write a C program to print the given star patterns.
  53. Number pattern programs - Write a C program to print the given number patterns.



Any doubt or suggestion write here. I will try my best to help. Before posting your code you must escape it to view. To format your source code and use format highlighting, post your source code inside
< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).

2 comments: