You are on page 1of 11

LOOPING EXERCICES

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 enter any number and find its first and last digit.
11. Write a C program to enter any number and calculate sum of its digits.
12. Write a C program to enter any number and calculate product of its digits.
13. Write a C program to swap first and last digits of any number.
14. Write a C program to enter any number and print its reverse.
15. Write a C program to enter any number and check whether the number is palindrome or not.
16. Write a C program to enter any number and print it in words.
17. Write a C program to print all ASCII character with their values.
18. Write a C program to find power of any number using for loop.
19. Write a C program to enter any number and find the sum of first and last digit of the number.
20. Write a C program to enter any number and print all factors of the number.
21. Write a C program to enter any number and calculate its factorial.
22. Write a C program to find HCF (GCD) of two numbers.
23. Write a C program to find LCM of two numbers.
24. Write a C program to enter any number and check whether it is Prime number or not.
25. Write a C program to enter any number and check whether it is Armstrong number or not.
26. Write a C program to enter any number and check whether it is Perfect number or not.
27. Write a C program to enter any number and check whether it is Strong number or not.
28. Write a C program to print all Prime numbers between 1 to n.
29. Write a C program to print all Armstrong numbers between 1 to n.
30. Write a C program to print all Perfect numbers between 1 to n.
31. Write a C program to print all Strong numbers between 1 to n.
32. Write a C program to enter any number and print its prime factors.
33. Write a C program to find sum of all prime numbers between 1 to n.
34. Write a C program to print Fibonacci series up to n terms.
35. Write a C program to find one's complement of a binary number.
36. Write a C program to find two's complement of a binary number.
37. Write a C program to convert Binary to Octal number system.
38. Write a C program to convert Binary to Decimal number system.
39. Write a C program to convert Binary to Hexadecimal number system.
40. Write a C program to convert Octal to Binary number system.
41. Write a C program to convert Octal to Decimal number system.
42. Write a C program to convert Octal to Hexadecimal number system.
43. Write a C program to convert Decimal to Binary number system.
44. Write a C program to convert Decimal to Octal number system.
45. Write a C program to convert Decimal to Hexadecimal number system.
46. Write a C program to convert Hexadecimal to Binary number system.
47. Write a C program to convert Hexadecimal to Octal number system.
48. Write a C program to convert Hexadecimal to Decimal number system.
49. Write a C program to print Pascal triangle upto n rows.
50. Star pattern programs - Write a C program to print the given star patterns.
Star patterns are a series of '*' or any other character that are used to create some patterns or any
geometrical shape such as - square, triangle(Pyramid), rhombus, heart etc. These patterns are often
prescribed by many programming books and are best for practicing loops in programming and to
enhance logical thinking capability. Before printing any star pattern you must have knowledge of loops
and basic of pattern printing (Logic to print star patterns and shape).
51. List of various star pattern series * *
and solution in C: *****
***** 8. Hollow right triangle
* * *
**
* *
***
* *
****
***** *****
2. Hollow Square 9. Mirrored right triangle
***** *
**
*****
* *
***** * *
***** *****

***** 10. Hollow mirrored right triangle


3. Rhombus *****
***** ****
* * ***
* * **
* * *
*****
11. Inverted right triangle
4. Hollow Rhombus *****
***** * *
***** * *
***** **
***** *
*****
12. Hollow inverted right triangle
5. Mirrored Rhombus
*****
*****
****
* *
***
* *
**
* *
*
*****
13. Inverted mirrored right triangle
6. Hollow mirrored Rhombus
*****
* * *
** * *
*** **
**** *
*****
14. Hollow inverted mirrored right triangle
7. Right triangle *
* ***
** *****
* * *******
********* *****
15. Pyramid (Equilateral triangle) *******

* *********

* * *******

* * *****

* * ***

********* *

16. Hollow Pyramid 21. Diamond


**********
*********
**** ****
*******
*** ***
*****
** **
***
* *
*
* *
17. Inverted Pyramid ** **
********* *** ***
* * **** ****
* * **********
* *
22. Hollow diamond
*
*****
18. Hollow inverted pyramid ****
* ***
** **
*** *
**** **
***** ***
**** ****
*** *****
**
23. Right Arrow
*
*****
19. Half diamond ****
* ***
** **
*** *
**** **
***** ***
**** ****
*** *****
**
24. Left arrow
*
20. Mirrored half diamond
***** *****
******* *******
* ********* *********
*** *******************
***************** *******
*************** *****
************* ***
*********** *
********* 25. Heart Star pattern
52. Number pattern programs - Write a C program to print the given number patterns.

Number patterns are logical programs that basically are used to enhance your logical thinking abilities. These
patterns are patterns created by numbers and are similar to star patterns. Enhance your logical thinking abilities
by coding these patterns. Here is a list of basic, advanced, tricky and popular number patterns with logic and
explanation.

Pascal triangle 01010

01010

Number pattern 3

11111

10001

10001
11111
10001
11111
11111
11111
Number pattern 4
11111
11111
11111
1 1
Number pattern 1
1 1
11111
1 1
00000
11111
11111
Number pattern 5
00000
11111
11111
11111
Number pattern 2
11011
01010
11111
01010
11111
01010
Number pattern 6 12345

10101 12345

01010 12345

10101 12345

01010 Number pattern 11

10101 12345

Number pattern 7 23456

11011 34567

11011 45678

00000 56789

11011

11011 Number pattern 12

Number pattern 8 1 2 3 4 5

6 7 8 9 10

10001 11 12 13 14 15

01010 16 17 18 19 20

00100 21 22 23 24 25

01010 Number pattern 13

10001 12345

Number pattern 9 23455

11111 34555

22222 45555

33333 55555

44444 Number pattern 14

55555 55555

Number pattern 10 45555

12345 34555
23455 Number pattern 19

12345 55555

Number pattern 15 44445

12345 33345

23451 22345

34521 12345

45321 Number pattern 20

54321 54321

Number pattern 16 54322

54333

12345 54444

21234 55555

32123 Number pattern 21

43212 12345

54321 22345

Number pattern 17 33345

54321 44445

43212 55555

32123 Number pattern 22

21234 555555555

12345 544444445

Number pattern 18 543333345

55555 543222345

54444 543212345

54333 543222345

54322 543333345

54321 544444445
555555555 4444

Number pattern 23 333

1 2 3 4 5 22

16 17 18 19 6 1

15 24 25 20 7 Number pattern 28

14 23 22 21 8 11111

13 12 11 10 9 2222

Number pattern 24 333

1 44

22 5

333 Number pattern 29

4444 11111

55555 2222

Number pattern 25 333

1 44

22 5

333 Number pattern 30

4444 5

55555 44

Number pattern 26 333

55555 2222

4444 11111

333 Number pattern 31

22 5

1 44

Number pattern 27 333

55555 2222
11111

Number pattern 32 1

21

1 321

12 4321

123 54321

1234 Number pattern 37

12345 1

Number pattern 33 21

1 321

12 4321

123 54321

1234 Number pattern 38

12345 54321

Number pattern 34 4321

12345 321

1234 21

123 1

12 Number pattern 39

1 54321

Number pattern 35 4321

12345 321

1234 21

123 1

12 Number pattern 40

1 5

Number pattern 36 54
543

5432 Number pattern 45

54321 5

Number pattern 41 45

5 345

54 2345

543 12345

5432 Number pattern 46

54321 12345

Number pattern 42 2345

54321 345

5432 45

543 5

54 Number pattern 47

5 12345

Number pattern 43 2345

54321 345

5432 45

543 5

54 Number pattern 48

5 1

Number pattern 44 23

5 345

45 4567

345 56789

2345 Number pattern 49

12345 1
23 9

345 Number pattern 54

4567 1

56789 123

Number pattern 50 12345

56789 1234567

4567 123456789

345 Number pattern 55

23 1

1 123

Number pattern 51 12345

56789 1234567

4567 123456789

345 Number pattern 56

23 1

1 24

Number pattern 52 135

13579 2468

3579 13579

579 Number pattern 57

79 1

9 2 3

Number pattern 53 4 5 6

13579 7 8 9 10

3579 11 12 13 14 15

579 Number pattern 58

79