Cse Assignment 3
Cse Assignment 3
Cse Assignment 3
STEP 1: START
STEP 2: ENTER a , b
STEP 3: PRINT a , b
STEP 4: a = a + b
STEP 5: b = a - b
STEP 6: a =a - b
STEP 7: PRINT a, b
STEP 8: END
2. Write an algorithm and a program for calculation of factorial of an
input number n.
STEP 1 : START
STEP 5 : Calculate f = f * i
STEP 6 : Print f
STEP 7 : END
3. Write an algorithm and a program for generation of first n terms of
Fibonacci sequence.
Step 1: START
Step 2: Take a number for user
Step 3: Initialise a=o and =1
Step 4: Take a loop up to n number and then move to step4
Step 5: The value of a=a + b and b=a + b
Step 6:print a and print b
Step 7: STOP
4. Write an algorithm and a program for converting a character to a
decimal value.
STEP 1: START
STEP 4: END
5. Write an algorithm and a program for finding the smallest divisor of
an integer.
Step 1: START
Step 2: Take a user input as n
Step 3: initialise i=n
Step 4: use while loop such that i>1, then move to step5
Step 5: Again under whileloop if n%i==0,then p=I such
that i=-1,then move to step 6:
Step 6: Print p
Step 7: STOP
6. Write an algorithm and a program for generating the prime numbers
Step 1: START
Step 2: Take user input as n.
Step 3: initailise the variable c=0.
Step 4: take a loop from range 2to n//2+1 and c=1.
Step 5: if c==0, then move to step 6 else step7
Step 6: print the number(n)is prime.
Step 7: print the number is composite number.
Step 8: STOP
7. Write an algorithm and a program for counting the prime factors of
an integer
Step 1: START
Step 2: take a number from user input, create a function
named isprime(a)
Step 3: intialize the loop from 2 to a//2+1 and if a%i==0
then return false else true.
Step 4: initialize another variable c=0
Step 5: again initailse another loop from 2 to n+1 and if
n%i==0 and then go to step6.
Step 6: if n%i ==0 then move to step7.
Step 7: if isprime(i) then c+=1.
Step 8: print (the of prime factor “c”)
Step 9: STOP
8. Write an algorithm and a program for generating pseudo-random
numbers.
Step 1: start
Step 2: import random
Step 3: Take an input from user as n for defing the range.
Step 4: Use random.randint function of random from1 to
n and store that in “r” variable
Step 5: Print r.
Step 6: Stop
9. Write an algorithm and a program for computing x^n where x is an
integer and nis a positive integer greater than 1.
Step 1: START
Step 2: Take two user input for first for a number(“x”)
and second for power(“n”).
Step 3: Create a variable p such that p= x**n
Step 4: Print (p).
Step 5: STOP
10. Write an algorithm and a program for finding the nth term of the
Fibonacci sequence.
Step 1: START
Step 2: Take a number for user as n
Step 3: Initialise a=o and b=1
Step 4: Take a loop upto n-2 number and then move
to step5
Step 5: Initialize the variable c such that c=a + b and
a=b and b=c
Step 6: Print c
Step 7: STOP