Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

1. Write a program to find Greatest Common Divisor or HCF of two numbers.

Program:
Algorithm:
1. Start
2. Input two numbers.
3. Find the smaller number.
4. Iterate from 1 to smaller number.
5. Check if both numbers are divisible
by iteration.
6. If the condition is satisfied update
the value of HCF with the current
iteration.
7. Print the calculated value of HCF.
8. Stop.
Output:

2. Write a program to find the Factorial of number ‘n’ using recursive function.
Program:

Algorithm:
1. Start.
2. Define a recursive function that computes the factorial
of a given number.
3. Obtain user input for value of ‘n’.
4. Call the defined factorial function.
5. Print the calculated Factorial of ‘n’.
6. Stop.

Output:

3. Write a program to generate first ‘n’ Fibonacci numbers.


Program:
Algorithm:
1. Start.
2. Set first two numbers in
series as 0 and 1.
3. Input ‘n’ as the number of
elements in the series to print.
4. Generate and print the
elements in the loop till the
n’th element.
5. Stop.
Output:
4. Build a program called ‘GuessMyNumber’. The computer will generate a random number
between 1 and 10. The user types in a number and the computer replies “lower” if the random
number is lower than the guess, “higher” if the random number is higher, and “correct” if the
guess is correct. The player can continue guessing until the guess is right.

Program:

Algorithm:
1. Start.
2. Get a random number using
randint function.
3. Input the guess from the user.
4. If guess>number say lower
if guess<number say higher
if guess=number say Correct.
5. Repeat till user guesses the
number.
6. Stop

Output:
5. Write a Binary Search function which searches an item in a sorted list. The function should
return the index of each element to be searched in the list.

Program:
Algorithm:
1. Start.
2. Input a sorted array
and a number to be
found.
3. Set low to 0 and
high to length of list-
1.
4. Find middle element
and compare with the
number to be found.
5.If mid<num, right
if mid>num, left
6. Repeat till number is
found.
7. Print position of
number.
8. Stop.

Output:

6. Write a Bubble sort function to sort a given list. Print the original and sorted lost.

Program:

Output:

Algorithm:
1. Start.
2. Input a list to be sorted.
3. Compare each element with next number till all the conditions are satisfied.
4. This will sort the list.
5. Stop
7. Write a program to remove all punctuations from the string provided by the user.
Program:
Algorithm:
1. Start.
2. Input the string.
3. Compare each character with
function isalnum() and
eliminate all punctuations.
4. Print the modified string.
5.Stop.
Output:

8. Write a python program that accepts a sentence and calculates the number of words, digits,
uppercase letters and lowercase letters.
Program:
Algorithm:
1. Start.
2. Input sentence as input.
3. Count the numbers of
words, digits, uppercase and
lowercase letters.
4. Print the original string
with all counts.
5. Stop.

Output:

You might also like