0% found this document useful (0 votes)
92 views5 pages

Nested Loops (Iterations) Programs

Uploaded by

foooffadh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views5 pages

Nested Loops (Iterations) Programs

Uploaded by

foooffadh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Nested Loops (Iterations)

1. Write a program to display the pattern, given below:


1
22
333
4444
55555
2. Write a program to display the pattern, given below:
*
***
*****
*******
*********
3. Write a program to input any ten numbers and display all possible factors of each
number.
4. Write a program to display all 'Abundant' number from 10 to 100. An 'Abundant'
number is a number for which the sum of its proper divisors (excluding the number
itself) is greater than the number itself.
For example: take a number (say, 12)
Factors of 12= 1, 2, 3, 4, 6
Sum of factors= 1+2+3+4+6= 16
Since, 16>12, thus, 12 is an Abundant number.
The first few abundant numbers are 12, 18, 20, 24, 30, 36, 40, ………………….
5. Write a program to display the given pattern:
1
12
123
1234
12345
6. Write a program to display the given pattern:
1
35
7 9 11
13 15 17 19
21 23 25 27 29
7. Write a program to display the given pattern:
54321
4321
321
21
1
8. Write a program to display the given pattern:
97531
9753
975
97
9
9. Write a program to display the given pattern:
1234567
12345
123
1
10. Write a program to display the given pattern:
1
10
101
1010
10101
11. Write a program to display the given pattern:
*
**
***
****
*****
12. Write a program to display the given pattern:
11111
22222
33333
44444
55555
13. Write a program to find the sum of the factorial of all the natural numbers from 1 to n.
(Hint: Factorial of 5! = 5*4*3*2*1)
S = 1! + 2! + 3! + 4! + ………………………….. +n!
14. Write a program to generate a triangle or an inverted triangle till 'n' terms based upon
user's choice of triangle to be displayed.
Example 1: Example 2:
Input: Type 1 for a triangle Input: Type 2 for an inverted triangle
Enter your choice: 1 Enter your choice: 2
Enter the number of terms: 5 Enter the number of terms: 6
Sample Output: Sample Output:
1 666666
22 55555
333 4444
4444 333
55555 22
1
15. Write a program to accept any 20 numbers and display only those numbers which are
prime.
Hint: A number is said to be prime, if it is divisible only by 1 and the number itself.
16. Write a program to compute and display the sum of the following series:
1+2 1+2+3 1+2+3+ …………………….+𝑛
S= 1∗2 + + ……………………….. + 1∗2∗3∗…………………………∗𝑛
1∗2∗3
17. Write two separate programs to generate the following patterns using iteration (loop)
statements:
a. * b. 5 4 3 2 1
*# 5432
*#* 543
*#*# 54
*#*#* 5
18. Write a program to calculate and display the factorials of all the numbers between 'm'
and 'n' (where m0, n>0).
[Hint: factorial of 5 means: 5!=5*4*3*2*1]
19. Write a menu driven program to display all prime and non-prime numbers from 1 to
100.
Enter 1: to display all prime numbers
Enter 2: to display all non-prime numbers
Hint: A number is said to be prime if it is divisible only by 1 and the number itself.
20. Write a program to input a number and perform the following tasks:
a. to check whether it is a prime number or not
b. to reverse the number
If the number as well as its reverse is also 'Prime' then display 'Twisted Prime
otherwise 'Not a twisted Prime'.
Sample Input: 367
Sample Output: 167 and 761 both are prime.
It is a 'Twisted Prime'.
21. Write a program to display the factorial of any ten numbers.
[Hint: Factorial of 5! = 5*4*3*2*1]
Sample Input: 8
Factorial of 8= 40320
Factorial of 11= 39916800
and so on ……………………..
22. Write a program to input a number. Calculate and display the factorial of each digit.
Sample Input: 365
Factorial of 5= 120
Factorial of 6= 720
Factorial of 3= 6
23. Write power a program to input a three-digit number. Display its digits raised to the of
their respective position.
Sample Input: 465
Sample Output: 51 = 5
62 = 36
43 = 64
[Hint: 5 is at Unit's place, 6 is at Ten's place and 4 is at Hundredth's place.]
24. Write a program to display all composite numbers from 1 to 100. A number is said to
be composite, if it has two or more factors excluding 1 and the number itself.
Sample Input: 6
Sample Output: Factors of 6 are 2 and 3
Hence, 6 is a composite number.
Few composite numbers are 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, .....
25. Write programs to find and display the sum of the given series:
1 1 1 1
a. S = 1 + 2! + 3! + 4! + ……………………….. + 𝑛!
b. S = 1 + (1+2) + (1+2+3) + ……………………………. + (1+2+3+………….+n)
c. S = 1 + (1*2) + (1*2*3) + …………………………….. + (1*2*3*……………*n)
1 1 1
d. S = 1 + 1+2 + 1+2+3 + ……………………….. + 1+2+3+⋯…………..+ 𝑛
1 1 1 1 1 1
e. S = 2 + 3 + 5 + 7 + 11 + ……………………….. + 29
26. Write the programs to display the following patterns:
a. 1 c. 54321
21 5432
321 543
4321 54
54321 5
b. 1 2 3 4 5 d. 13579
1234 1357
123 135
12 13
1 1
e. 5 h. 9
54 79
543 579
5432 3579
54321 13579
f. 1 2 3 4 5 i. 9
2345 97
345 975
45 9753
5 97531
g. 9 9 9 9 9 j. 1
77777 2 3
55555 4 5 6
33333 7 8 9 10
11111 11 12 13 14 15

You might also like