# Exercise questions: Loops

1. WAP to print counting 1 to n.

Solution:

2. WAP to find sum of n natural numbers.

Solution:

3. WAP to find factorial of input number.

Solution:

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

Solution:

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

Solution:

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

Solution:

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

Solution:

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

Solution:

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

Solution:

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

Solution:

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

Solution:

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

Solution:

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

Solution:

14. WAP to count number of digits.

Solution:

15. WAP to find sum of digits.

Solution:

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

Solution:

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:

20. WAP to calculate LCM of 2 input numbers.

Solution:

21. WAP to calculate HCF of 2 input numbers.

Solution:

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

Solution:

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

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