PP Loop
PP Loop
1. Write a program that takes two integer x and n and computes x^n.
2. Write a program that takes an integers and determines if it is prime or not.
3. Write a program that finds out all the divisors of a number.
4. Write a program that takes an integer n and computes factorial of n. (n!)
5. Write a program that takes takes n integers and finds out the maximum/minimum.
6. Write a program that takes as input an integer and computes the sum of the following
series upto nth term.
a. 1 + 2 + 3 + ... ... + n
b. 12 + 22 + 32 + ... ... + n2
c. 11 + 12 + 13 + ... ... + 1n
1 1 1 1
d. 1 + 2 + 3 + ... ... + n
e. 2 + 4 + 6 + ... ... upto nth term
f. 2 + 4 + 8 + 16 + ... ... upto nth term
g. 1 − 2 + 3 − 4 ... ... upto nth term
7. Write a program that reverses the digits of an integer n. (For example, if the given
integer is 1234 you program should output 4321)
8. Write a program that determines whether n is a perfect number. A perfect number is a
number such that the sum of its divisors is equal to the number. Example of a few
perfect numbers are 6, 28, 496, 8128.
9. Write a program that prints all the prime numbers that is less than a given integer n.
10. Practice each of the above problems with different types of loops i.e. for loop, while loop,
do-while loop.