CPG Practical File
CPG Practical File
PRAC
TICAL
FILE
SHREYA SINGH
2023/BAE/143
SECTION-B
Practical 1- ALGORITHMS AND PSEUDOCODES
Questions:
Q1. Write an algorithm to determine the maximum of two
numbers.
Ans.
1. Start
2. Input the first number (A)
3. Input the second number (B)
4. If A is greater than B
4.1 Set max number as A
Else
4.2 Set max number as B
5. Display max number as the maximum of the two numbers
6. Print
Q2. Write an algorithm to determine the average of 3 numbers.
Ans.
1. Start
2. Input the first number (X)
3. Input the second number (Y)
4. Input the third number (Z)
5. Add X , Y and Z to get the SUM
6. Divide the sum by 3 to calculate the average
6.1 Set average as SUM divided by 3
7. Display the average as the result
8. End
QUESTIONS
Q3. Write an algorithm and draw a flowchart to convert length
in feet to length in centimetres.
Ans.
1. Start
2. Input the length in feet
3. Multiply the length in feet by 30.48 ( 1 foot = 30.48 cm)
3.1 Set length in cm as length in feet * 30.48
4. Display the length in cm
5. End
Q4. Write an algorithm and draw a flowchart that will read the
two sides of a rectangle and calculate its area.
Ans.
1. Start
2. Input the length of one side of the rectangle (A)
3. Input the length of the other side of the rectangle (B)
4. Calculate the area of the rectangle
4.1 Set area as side1 multiplied by side2
5. Display the calculated area as the result
6. End
START
INPUTSIDES
(A and B)
AREA=A*B
PRINT
AREA
STOP
QUESTIONS
Q5. Write an algorithm and draw a flowchart that will calculate
the roots of a quadratic equation.
Ans.
1. Start
2. Input the coefficients a, b, and c of the quadratic equation ax^2 +
bx + c = 0
3. Calculate the discriminant (D) using the formula: D = b^2 - 4ac
4. If D < 0, display "No real roots exist."
5. If D = 0, calculate the single root using the formula: root = -b / (2a)
6. If D > 0, calculate two distinct roots using the formulas:
root1 = (-b + √D) / (2a)
root2 = (-b - √D) / (2a)
7. Display the roots or root obtained in steps 5 and 6.
8. End
Q6. Write an algorithm and draw a flowchart to calculate the
marks of a student in 4 subjects and assign Pass if the average
marks are greater than 50, else fail.
Ans.
ALGORITHM
1. Start
2. Initialize variables SUB1, SUB2, SUB3, SUB4, total marks,
average marks.
3. Read input for SUB1, SUB2, SUB3, SUB4.
4. Calculate total marks = SUB1 + SUB2 + SUB3 + SUB4.
5. Calculate average marks = total marks / 4.
6. If average marks > 50, then
7. Display "Pass"
Else
Display "Fail"
8. End
Q7. Write an algorithm and draw a flowchart that reads two
values, determines the largest value and prints the largest value
with an identifying message.
Ans.
1. Start
2. Input value1
3. Input value2
4. If value1 > value2
5. Print "The largest value is value1 "
6. Else
7. Print "The largest value is value2"
8. Stop
Q8. Write an algorithm and draw a flowchart to find the greatest
of the three numbers.
Ans.
1. Start
2. Input three numbers: num1, num2, num3
3. If num1 is greater than num2 and num1 is greater than num3,
then,
Display num1 as the greatest number
4. Else, if num2 is greater than num1 and num2 is greater than
num3, then
Display num2 as the greatest number
5. Else,
Display num3 as the greatest number
6. End
Q9. Write an algorithm and draw a flowchart to find out
whether the number entered by user is even or odd.
Ans.
1. Start
2. Input a number: num
3. If num modulo 2 equals 0, then
Display "The number is even"
4. Else,
Display "The number is odd"
5. End
START
ENTER A
NUMBER
IS NUM
%2==0
PRINT ODD
PRINT EVEN
STOP
Q10. Write the program to take two numbers as input from the
user and provide a menu for calculations on those two
numbers
as per the operation selected by the user.
Ans.
1.Prompt the user to enter two numbers.
2.Read and store the two numbers in separate variables, let's
say num1 and num2.
3.Display a menu with options for different operations, such as
addition, subtraction, multiplication, and division.
4.Ask the user to choose an operation by entering a
corresponding number or character.
5.Based on the user's choice, perform the selected operation
and display the result.
6.Repeat the process until the user chooses to exit the
program.
INPUT n
Q5. Write an algorithm and draw a flowchart to compare the
sum of first n natural numbers where n is taken as input from the
NO
user. YES
IS
Ans. n==0
1. Start END
2. Input a number 'n' as the limit for natural numbers
Initiative
3. Calculate the sum of the first 'n' natural numbers (sum1) using
I=n
the formula: sum1 = (n * (n + 1)) / 2
4. Calculate the sum of the next 'n' natural numbers (sum2) using
the formula: sum2 = ((n * (n + 1)) / 2) - (n * (n - 1)) / 2
5. IfIS sum1 is greater than sum2, then
Display
i>/1? "The sum of first 'n' natural numbers is greater"
6. Else if sum1 is less than sum2, then
Display "The sum of next 'n' natural numbers is greater"
PRINT
7. Else,
Display "Both sums are equal"
8. End
I=i-1 START
INPUT N
SUM=0
I=i=1
I<=n
?
SUM=SUM+i
I=i+1
Print sum
STOP
Q14. Write an algorithm and draw a flowchart to print sum of
even numbers between 1 to n where n is taken as input from
the user.
Ans.
Step 1: Start
Step 2: Read the limit of numbers, n
Step 3: Assign i=1
Step 4: Assign sum=0
Step 5: Repeat steps 6,7&8 until i=n reaches
Step 6: If i%2==0 go to step 7
Step 7: Compute sum= sum+i
Step 8: Compute i=i+1
Step 9: Print sum of even numbers, sum
Step 10: Stop.
Q15. Write an algorithm and draw a flowchart to print the
series 1,2, 4, 8, 16, 32, 64.
Ans.
1. Start
2. Set a variable 'num' to 1
3. Repeat the following steps six times:
Display the value of 'num'
Multiply 'num' by 2
4. End
Practical 4 – Case structure
2)MEDIAN FUNCTION
The MEDIAN function in Excel is used to find the middle
value in a set of numbers. It's a statistical function that
can be helpful for determining the central or typical
value in a data set. =MEDIAN(number1, [number2], ...)
3)MAX Function:
The "MAX" function returns the largest value from a
range of numbers.
MIN Function:
The "MIN" function, on the other hand, returns the
smallest value from a range of numbers.
4)STEP DEVIATION METHOD
In statistics, the concept of "step deviation" or "step
data" typically refers to data that has been adjusted by
subtracting a constant value from each data point. This
adjustment is often used when you want to perform
calculations or create a new dataset with a more
manageable range of values, which can be especially
useful when working with data that has a wide range or
large numerical values.
5)SUM IFS
The SUMIFS function in Excel allows you to sum values
based on multiple criteria or conditions. It's useful when
you want to calculate the sum of values that meet
specific conditions simultaneously