Cad22 3 Lab Programs
Cad22 3 Lab Programs
1. Write a program for addition, subtraction, multiplication and division of two numbers
ALGORITHM:
STEP 1: Display choice of operation in screen, “Choice 1: Add, 2: Sub, 3: Div, 4: Mul, 5: Quit “.
STEP 2: Receive input choice from the user.
STEP 3: Convert the input to integer (n = int (n1)).
STEP 4: If choice of option is 1 then receive input for A and B, Initiate operation c = A + B.
STEP 5: If choice of option is 2 then receive input for A and B, Initiate operation c = A - B.
STEP 6: If choice of option is 3 then receive input for A and B, Initiate operation c = A / B.
STEP 7: If choice of option is 4 then receive input for A and B, Initiate operation c = A * B.
PROGRAM:
Exit.
FIBONACCI SERIES
ALGORITHM:
“Fibonacci Series is a number series, where each number is a addition of preceding two number” (ie .
if n= 5 then Fibonacci number series are : 0,1,1,2,3.).
STEP 2: Prompt the user to enter the number (ie. 1 to n , any integer number).
STEP 3: Since python accept any input in string format, change the input n1 from string to
integer n (ie. n = int(n1)).
PROGRAM:
SAMPLE OUTPUT:
Fibonacci Series
3
FIZZ BUZZ PROGRAM
3. Write a program to incorporate FIZZ for any number divisible by 3 and Buzz for any
number
divisible for 5 and FIZZBUZZ for any number divisible by 3 and 5 as well.
ALGORITHM:
else
Print I Value
PROGRAM:
FizzBuzz Program
3 = FIZZ
5 = BUZZ
9 = FIZZ
10 = BUZZ
11
12 = FIZZ
13
14
15 = FIZZBUZZ
AIM:
To write a Python program to display reverse string.
ALGORITHM:
STEP4: Count the characters in the string variable and subtract with -1.
Store
the result in the variable i.
STEP5: While variable “i” is greater than and equal to zero then
i=i–1
PROGRAM:
i = len(string) - 1
i = i - 1
OUTPUT:
AIM:
To write a Python program to display a multiplication table.
ALGORITHM:
STEP 1: Receive input from user that the number he/she wants to multiply
and store it in a variable m.
STEP 2: Receive input from user that the number times he/she wants to
multiply the number and stored it in variable n.
STEP 3: Initialize i = 1
FLOW CHART:
START
Receive input from user that the number he/she wants to multiply and store it in a variable
m.
Receive input from user that the number times he/she wants to multiply the number and
stored it in variable n.
Initialize i = 1
YES
STOP
PROGRAM:
print ("\t\t**********************");
print ("\n\n");
i = 1
print ("\t\t",m,"x",i,"=",c);
i = i+1
OUTPUT:
MULTIPLICATION TABLE
**********************
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70
7 x 11 = 77
7 x 12 = 84
7 x 13 = 91
7 x 14 = 98
7 x 15 = 105
7 x 16 = 112
7 x 17 = 119
7 x 18 = 126
7 x 19 = 133
7 x 20 = 140
6. Write a Python program to display all prime numbers between 1 to 1000.
AIM:
To write a Python program to display all prime numbers between 1 to 1000.
ALGORITHM:
STEP 3: Create outer for loop to i value execute from lower range to upper
range value times
STEP 5: Create a inner for loop to j value to execute from 1 to i+1 times
FLOW CHART:
START
for i in range NO
(lower,upper + 1)
YES
count = 0
YES
NO if (i % j) == 0:
YES
count = count + 1
NO if (count == 2):
YES
print(i)
STOP
PROGRAM:
count = 0
for j in range(1,i+1):
if (i % j) == 0:
count = count + 1
if (count == 2):
print(i)
OUTPUT: