Lab Session 9 PDF
Lab Session 9 PDF
Lab Session 9
Task 1:
Write a program to find the sum of the following series:
Task 2:
Repeat the Task 1 of the last Lab Session 7 i.e. finding the factorial of the input number, using while
statement.
Task 3:
Modify above task such that after calculating the factorial, it asks again from user if he/she wants to
calculate the factorial again for some new integer.
Task 4: (Difficult!)
A number is known as to be a palindrome if it same in reverse order e.g. 1331, 4536354, 787 are
palindromes and 1330 and 1778 are not. Write a program using while loop to that will take a number
from user as input and will display if the number is palindrome or not. Define number as unsigned int
to have wide range.
How to do it:
Input the number. Create a new number with reverse order. It can be done by writing a while loop, get unit
digit of the number and start producing a new number from remainder. For example if number is 5623,
you have to create a new number with reverse order. It can be done by dividing 5623 by 10, you will get
562 and remainder 3 which is the first digit of reverse number. Now again divide 562 by 10, you will get 56
and 2. Combine this remainder with the previous one and you will get 32. Repeat this process until the
quotient becomes 0 and you will get the reverse number 3265. Compare it with the input to decide
whether it is a palindrome or not.