0% found this document useful (0 votes)
26 views3 pages

Lab 3 IPP

Uploaded by

Asmit patra
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)
26 views3 pages

Lab 3 IPP

Uploaded by

Asmit patra
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
You are on page 1/ 3

Programming Assignment-III

(Iterative Statements/Looping)
1. Write a program that gets three integers from the user. Count from the first number to
the second number in increments of the third number.
from: 5

to: 18
step by: 2
Output: 5 7 9 11 13 15 17

2. Find output:
a)

number = 72958476
a, b = 0, 0
while (number > 0):
digit = number % 10
if(digit % 2 != 0):
a += digit
else:
b += digit
number /= 10
print(a,b)

b)

total = 0
N=5
for i in range(1, N+1):
for j in range(1, N+1):
total += i
print(total)

3. Write a program that prints the integers from1,000 to 2,000 with five integers per line.
4. If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
The sum of these multiples is 23. Write a program to find the sum of all the multiples of 3 or
5 below a user entered number N.
5. Write a program to print the following pattern using nested loops.
6. Write a program to print the following pattern using nested loops.
* * * * * * * * * * 1
* * * * * * 2

* * * * 3
* * * * 4

* * * 5
* * * * 6
* * 7
* * * * 8
* * * 9
* * * * 10
7. Write a program to compute the harmonic mean. The harmonic mean is defined by

8. Write a program to compute the sum of the first n terms (n>=1) of the series.

S=1-3+5-7+9- ………
9. Input a number n, write a program to compute n factorial (written as n!) where n>=0.
10. For a given x and a given n, write a program to compute xn/n!.
11. Write a program to generate and print the first n terms of the Fibonacci sequence where
n>=1. The first few terms are: 0, 1, 1, 2, 3, 5, 8, 13, ......
12. Write a program to generate and print the first n terms of the following sequence where
n>=1. The first few terms are: 1, 2, 3, 6, 11, 20, 37, ......

13. Write a program that accepts a positive integer n and reverses the order of its digits.

14. Write a program that puts the binary representation of a positive integer N into aString s.
15. Write a program GCD that finds the greatest common divisor (gcd) of two integers using
Euclid’s algorithm, which is an iterative computation based on the following observation: if
x is greater than y, then if y divides x, the gcd of x and y is y; otherwise, the gcd of x and y
is the same as the gcd of x % y and y.

16. Write a program to find the sum of the first n terms of the series fs=0!+1!+2!+3!+…+n!
(n>=0)

17. Write a program to find the sum of the first n terms of the series s=x1/1!+x2/2!+x3/3!+….

18. Write a program to find the sum of the first n terms of the series s=x-x3/3!+x5/5!-x7/7!+….

19. Write a program to compute the sum of the digits in an integer.


20. A perfect number is one whose divisors add up to the number. Example: The first perfect
number is 6, because 1, 2, and 3 are its proper divisors, and 1+2+3=6.
Write a program that prints all perfect numbers in between 1 and 500.

You might also like