0% found this document useful (0 votes)
5 views30 pages

Exam

Exam paper imp

Uploaded by

vivek.anime7444
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)
5 views30 pages

Exam

Exam paper imp

Uploaded by

vivek.anime7444
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/ 30

1.

Write an algorithm to find maximum and minimum of


three numbers
•Input:
•Read the three numbers (a, b, c) from the user.
•Initialization:
•Set max to the first number (a).
•Set min to the first number (a).
•Comparison and Update:
•Compare b with max and min:
•If b is greater than max, update max to b.
•If b is less than min, update min to b.
•Compare c with max and min:
•If c is greater than max, update max to c.
•If c is less than min, update min to c.
•Output:
•Print the maximum and minimum values.
USING ARRAYS
2. Imagine you're organizing a photo shoot for a group of
friends. Each friend wants to take a photo in every
possible order, one after the other. If there are n friends,
how many unique photo arrangements can you create
where each friend stands in a different position every
time? Design a solution (algorithm) for this problem.
Problem Analysis:
This problem is essentially about finding the number of permutations
of ( n ) friends. In permutations, the order matters, and each friend
must stand in a different position every time.

Solution: Factorial

The number of unique photo arrangements (permutations) for ( n )


friends is given by ( n! ) (n factorial), which is the product of all
positive integers up to ( n ).

The number of permutations of n objects is given by n factorial,


denoted as n!.

Definition of n!: n! = n * (n-1) * (n-2) * ... * 2 * 1


Example: If there are 3 friends (A, B, C), the possible arrangements
are:
ABC
ACB
BAC
BCA
CAB
CBA
So, 3! = 3 * 2 * 1 = 6.
Algorithm:
Input: Number of friends ( n ).
Output: Number of unique photo arrangements.
Steps:
Initialize a variable result to 1.
Loop from 1 to ( n ):
Multiply result by the current loop index.
Return result.
3. Imagine you're a chef in a restaurant, and you want to
rate the quality of a dish based on three key ingredients:
taste, presentation, and freshness. Each ingredient is rated
on a scale from 0 to 100. If the average score of these
three ingredients is 90 or above, the dish is rated
as "Outstanding." If it's between 75 and 89, it's rated as
"A+." If the average is below 75, it’s rated as "A." Draw a
flowchart to determine the overall rating of the dish based
on these criteria.
Algorithm
•Read input:

•Read the taste score, presentation score, and freshness score from the user.

•Calculate average score:

•Calculate the average of the three scores.

•Determine rating:

•If the average score is greater than or equal to 90, set the rating to "Outstanding".
•Otherwise, if the average score is greater than or equal to 75, set the rating to "A+".
•Otherwise, set the rating to "A".

•Output rating:

•Print the overall rating of the dish.


6. Compute sum of digits of a given number. For example:
if the given number is 645.
Compute 6+4+5 which is equal to 15. Design an algorithm
for this purpose.
Algorithm
Input: A positive integer number

Output: The sum of the digits of number

Steps:
Initialize sum: Set a variable sum to 0.

Iterate:
•While number is not 0:

•Extract the last digit of number using the modulo


operator (% 10) and add it to sum.
•Remove the last digit of number by dividing it by 10
and truncating the result using integer division (// 10).

Return sum: Return the value of sum.


7. Design a flow chart to compute and display Fibonacci
series with n terms.
Algorithm
•Start: The process begins.
•Input n: The user enters the number of terms (n) for the Fibonacci series.
•Initialize: The first two Fibonacci numbers (f1=0, f2=1) and a counter
(i=2) are initialized.
•Check condition: If the counter (i) is less than or equal to the desired
number of terms (n), the process continues.
•Print f1: The current Fibonacci number (f1) is printed.
•Calculate next Fibonacci: The next Fibonacci number (f3) is calculated
by adding the previous two (f1 and f2).
•Update f1 and f2: The values of f1 and f2 are updated for the next
iteration.
•Increment counter: The counter (i) is incremented to move to the next
term.
•Repeat: The process returns to step 4 to check the condition and
continue generating the series until the desired number of terms is
reached.
•End: The process ends after printing the specified number of Fibonacci
terms.
8. You are a security guard at a museum, and you have to
decide how to place items on two
separate shelves. If the item number is evenly divisible
between two guards (no remainder),
you place it on the left shelf. If there's a leftover, you place
it on the right shelf. Draw a
flowchart to determine which shelf each item should go
on based on its item number.
Algorithm
Input:
Item number
Output:
Shelf (left or right)
Steps:
Read input:
Read the item number from the user.
Check divisibility:
If the item number is evenly divisible by 2 (no remainder), the
item should be placed on the left shelf.
Otherwise, the item should be placed on the right shelf.
Output result:
Print the shelf where the item should be placed (left or right).
10. Identifying the number of factors for a given number
can be applicable in various
problems like computing GCD, prime number etc. Develop
a flowchart that displays the
number of factors when an integer value is given as input.
Algorithm

•Start: The process begins.


•Input number: The user enters the number for which to find the factors.
•Initialize count: A counter variable count is initialized to 0 to store the number of
factors.
•Initialize i: A loop variable i is initialized to 1.
•Check condition: If i is less than or equal to the input number, the loop continues.
•Check divisibility: If the input number is divisible by i, it is a factor.
•Increment count: If i is a factor, the count is incremented.
•Increment i: The loop variable i is incremented to check the next number.
•Repeat: The process returns to step 5 to check the condition and continue
finding factors until i exceeds the input number.
•Print count: The final value of count, which represents the total number of factors,
is printed.
•End: The process ends.
THANK YOU

You might also like