Exercise questions: Loops

  1. WAP to print counting 1 to n.

    Solution: C

  2. WAP to find sum of n natural numbers.

    Solution: C

  3. WAP to find factorial of input number.

    Solution: C

  4. WAP to display all Even numbers from 1 to n.

    Solution: C Python

  5. WAP to generate multiplication table of an input number.

    Solution: C Java

  6. WAP to generate Fibonacci series: 0 1 1 2 3 5 8 … n

    Solution: C

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

    Solution: C

  8. WAP to generate the following series: 1 1 1 3 5 9 … n

    Solution: C

  9. WAP to print a sequence 1 3 6 10 15 21 … n

    Solution: C

  10. WAP to find input number is prime or not.

    Solution: C

  11. WAP to find an Input number is composite or not. (A composite number is a positive integer which is not prime).

    Solution: C

  12. WAP to calculate x power y. Eg. xy. Value of x and y is entered by user.

    Solution: C PHP

  13. WAP to reverse a number. E.g. Input: 123, Output: 321.

    Solution: C

  14. WAP to count number of digits.

    Solution: C

  15. WAP to find sum of digits.

    Solution: C

  16. WAP to Input number and find it is palindrome or not.

    Solution: C

  17. Find sum of series: 1 – 2 + 3 – 4 + 5 – 6 + 7 – 8 … n
  18. Find sum of series: 1 + 2 + 3 – 4 + 5 + 6 – 7 + 8 + 9 – 10 … n
  19. Find sum of series: 12 + 22 + 32 + 42 … n.

    Solution: C

  20. WAP to calculate LCM of 2 input numbers.

    Solution: C

  21. WAP to calculate HCF of 2 input numbers.

    Solution: C

  22. WAP to calculate the prime factors of input number. E.g. prime factor of 24 is 2, 2, 2 and 3.

    Solution: C

  23. 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);