1.
Write a program that calculates and produces these two columns sequence numbers using the
three looping statements:
Sequence nos. Squared
1 1
2 4
3 9
4 16
5 25
1st Solution – using for loop statement
2nd Solution – using while loop statement
3rd Solution – using do while loop statement
2. Write a program which produces the given sequence nos. (in alternate arrangement) using the
three looping statements:
1, 5, 2, 4, 3, 3, 4, 2, 5, 1,
1st Solution – using for loop statement
2nd Solution – using while loop statement
3rd Solution – using do while loop statement
3. Write a program which produces the given sequence numbers (in alternate arrangement and
reverse order of the problem no. 2) using the three looping statements:
5, 1, 4, 2, 3, 3, 2, 4, 1, 5,
1st Solution – using for loop statement
2nd Solution – using while loop statement
3rd Solution – using do while loop statement
4. Write a program to calculate the factorial value of the input number n! Use the incrementation
formula (i++) for your solution instead of decrementation formula (i–)
Which we had already use and applied in our previous example. Apply the three looping
statements for your solutions:
Sample input/output dialogue:
Enter a no. 4
Factorial value: 24
(The computation is: 1*2*3*4=24)
1st Solution – using for loop statement
2nd Solution – using while loop statement
3rd Solution – using do while loop statement
5. Write a program that generates and displays the Fibonacci sequence numbers of n (as input). In
Fibonacci, the current third number is the sum of two previous numbers. Apply three solutions
using the three loop statements:
Sample input/output dialogue:
Enter a no. 9
Fibonacci series: 1 1 2 3 5 8 13 21 34
1st Solution – using for loop statement
2nd Solution – using while loop statement
3rd Solution – using do while loop statement
6. 1st Solution – using for loop statement
2nd Solution – using while loop statement
3rd Solution – using do while loop statement
7. Write a program to scan a number n and then output the sum of the squares from 1 to n. Thus,
if the input is 4, the output should be 30 because:
12 + 22 + 32 + 42
1 + 4 + 9 + 16
=30
1st Solution – using for loop statement
2nd Solution – using while loop statement
3rd Solution – using do while loop statement
8. Write a program to calculate the sum of the sequence no. from 1 to n. Thus if the input is 6, the
output should be 21 because (Apply the three looping statements in your solutions)
1+2+3+4+5+6=21
1st Solution – using for loop statement
2nd Solution – using while loop statement
3rd Solution – using do while loop statement
9. Write a program that reverses the input number n. Formulate an equation o come up with the
answer (Apply the three loop statements in your solutions)
Sample input/output dialogue
Enter a number 1238 Input data
Reverse number 8321 Output value
1st Solution – using for loop statement
2nd Solution – using while loop statement
3rd Solution – using do while loop statement
10. Write a program to scan a number n and then output the sum of the powers from 1 to n. Thus, if
the input is 4, the output should be 288 because:
11 + 22 + 33 + 44
1 + 4 + 27 + 256 = 288
1st Solution – using for loop statement
2nd Solution – using while loop statement
3rd Solution – using do while loop statement