0% found this document useful (0 votes)
14 views

Lab External Ans

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Lab External Ans

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Q1) Design an algorithm and draw a flowchart to swap the values of two variables entered

by user.

A) Flowchart:

Algorithm:

Input: Any two numbers

Procedure:

Start

Step-1: Read two values from user into the variables a and b.

Step-2: Initialize the variable temp to a.


Step-3: Initialize the variable a to b.

Step-4: Initialize the variable b to temp.

Step-5: Print a and b.

Q2) Draw a flowchart and design an algorithm to compute factorial of any number entered
by

user.

A) Flowchart:

Algorithm

Input: A number

Procedure:

Step 1: Start
Step 2: initialize variable count to 1

Step 3: initialize variable result to 1

Step 4: repeat until count > n

Step 4.1: result = result * count

Step 4.2: count = count + 1

Step 5: Display value of ‘result’

Step 6: End

Output: Factorial of the number

Q3) Develop an algorithm and flowchart to reverse the digits of an integer entered by user.

A) Flowchart:
Algorithm:

Input: 1 number.

Procedure:

Start

Step-1: Read a value from user into the variable n.

Step-2: Initialize the variable s to 0.

Step-3: Repeat until the value of n becomes 0.

Step-3.1: r=n%10

Step-3.2: s=s*10+r
Step-3.3: n=floor(n/10)

End

Output: Reverse of given number.

Q4) Develop an algorithm and flowchart to compute the greatest common divisor of two
given integers.

A) Flowchart:

Algorithm:

Input: Two integer values.

Procedure:
Start

Step-1: Read two integer values from user into variable n1 and n2.

Step-2: If n1<n2

Least=n1

Else:

Least=n2

Step-3: Repeat x from 1 to least

Step-3.1: If n1 and n2 are divisible by x

gcd=x

Step-4: Display variable gcd

End

Output: Greatest common divisor.

Q5) Develop a python program to check whether given year is leap year or not.

Q6) Design a python program that prints numbers from “start” to “end” using while loop,
where “start” and “end” values are entered by user.

A)

Q7) Write a python program that prints multiplication table of any number entered by
user.

Allow the user to specify the table size also.

A)

Q8)Write a python program to check whether given number is prime or not.


Q9) Design a python program that takes a sentence as input and prints the first half and
second half separately.

A)

Q10) Develop a python program that processes a paragraph of text, counting the number
of words, finding the longest word, and converting the text to title case.

A)

Q11) Design a python program to implement bubble sort algorithm that sorts a list of item

quantities entered by the user.

A)

Q12) Design a python program to implement selection sort algorithm that sorts a list of
item quantities entered by the user.

A)
Q13) Perform set operations union,intersection and difference with the help of a python
program.

A)

Q14)Create a python program to generate list of squares of even numbers between 1,20.

A)

Q15)Create a program that models a library system using nested dictionaries.include


functionality to list books by genre.

A)
Q16)Develop a program to demonstrate how to (i) add and remove elements from
a list (ii) accessing elements in tuple.
A)

Q17)Design a python program to find factorial of a given number using recursion.

A)

Q18)Explain the concept of binary search on a list of values with an example


program
A)
Q19)Design a python program to find sum of natural numbers upto n using
recursion.
A)

Q20)Explain the concept of linear search on a list of values with an example


program.
A)

You might also like