Exercise questions: Loops

  1. WAP to print counting 1 to n.
  2. WAP to find sum of n natural numbers.
  3. Solution: C

  4. WAP to find factorial of input number.
  5. Solution: C

  6. WAP to display all Even numbers from 1 to n.
  7. Solution: C Python

  8. WAP to generate multiplication table of an input number.
  9. Solution: C Java

  10. WAP to generate Fibonacci series: 0 1 1 2 3 5 8 … n
  11. Solution: C

  12. WAP to generate Lucas Series: 2 1 3 4 7 11 18 … n
  13. Solution: C

  14. WAP to generate the following series: 1 1 1 3 5 9 … n
  15. Solution: C

  16. WAP to print a sequence 1 3 6 10 15 21 … n
  17. Solution: C

  18. WAP to find input number is prime or not.
  19. Solution: C

  20. WAP to find an Input number is composite or not. (A composite number is a positive integer which is not prime).
  21. Solution: C

  22. WAP to calculate x power y. Eg. xy. Value of x and y is entered by user.
  23. Solution: C PHP

  24. WAP to reverse a number. E.g. Input: 123, Output: 321.
  25. Solution: C

  26. WAP to count number of digits.
  27. Solution: C

  28. WAP to find sum of digits.
  29. Solution: C

  30. WAP to Input number and find it is palindrome or not.
  31. Solution: C

  32. Find sum of series: 1 – 2 + 3 – 4 + 5 – 6 + 7 – 8 … n
  33. Find sum of series: 1 + 2 + 3 – 4 + 5 + 6 – 7 + 8 + 9 – 10 … n
  34. Find sum of series: 12 + 22 + 32 + 42 … n.
  35. Solution: C

  36. WAP to calculate LCM of 2 input numbers.
  37. Solution: C

  38. WAP to calculate HCF of 2 input numbers.
  39. Solution: C

  40. WAP to calculate the prime factors of input number. E.g. prime factor of 24 is 2, 2, 2 and 3.
  41. Solution: C

  42. WAP to find number is perfect or not. Perfect numbers are: 6, 28, 496, 8128
Advertisement

24. How many times the following loops will be executed for the values of int i=7, j=250, k=55.

int count = 0;
for(i<k;i+=5)
{
   printf("%d", count);
   count++;
}

int count = 0;
do {
   printf("%d", count);
   i++;
   count++;
}while(j>i);