Uploaded by pavansaieducation

PavanSaiKappiri Internal1

advertisement
Pavan Sai Kappiri
[INTERNAL 1]
2024976
February 2, 2021
Q1 Find the product of individual digits of given number
Step 1
To find the product of the individual digits from the given number, first have to have to identify each
digit in the given number and then multiply.
Step 2
Input: - A Decimal Number
Process: - The decimal number should be divided by 10 to find the reminder, and must be multiplied
with X, and then the number should be rounded to the nearest integer and repeat the process until the
number is 0 or not greater than 0.
Output: - Display the results.
Step 3
Input
Decimal Number
Process
Identify and multiply individual
Digits.
Output
Product
Step 4; Algorithm
Step 1 Start
Step 2 R = 0, X = 1
Step 3 Input N
Step 4 R= N % 10
Step 5 X = X * R
Step 6 ROUND(N) = N/10
Step 7 N > 0 GoTo Step 4 or GoTo Step 8
Step 8 PRINT “Product of individual digits in a number” ;X
Step 9 End
Step 5: Testing Algorithm
Sample Value1: - 142
Sample output Value: - 8
R & X variables were initialized to 0 and 1. R is for Reminder and X is for the final product. As the number N
entered It will be divided by 10 and we use % function to find the reminder which then multiplies with X. N will be
further divided by 10 and rounded to nearest integer. Then a conditional statement is written if N meets the
condition then process repeats otherwise the final product of the digits is displayed.
Pavan Sai Kappiri
[INTERNAL 1]
2024976
February 2, 2021
Q2 Do any five arithmetic operations of a Calculator. Ask the
user to choose the operation choice from 1 to 5.
Step 1
We have to make use of the selection statement If then else end if in an algorithm for the user to select
the arithmetic operation.
Step 2
Input: - Decimal Numbers
Process: - Arithmetic operation should be chosen and decimal numbers should be entered.
Output: - Display the results.
Step 3
Input
Decimal numbers
Process
Selection of operation and doing the
Arithmetic functions.
Step 4; Algorithm
Step 1 Start
Step 2 A=0, S=0, M=0, D=0, P=0
Step 3 Print “Press 1 for Addition”
Step 4 Print “Press 2 for Subtraction”
Step 5 Print “Press 3 for Multiplication”
Step 6 Print “Press 4 for Division”
Step7 Print “Press 5 for Percentage”
Step 8 Input “Select an Operation to perform”; N
Step 9 N = 1 GOTO STEP 10 OR GOTO STEP 16
Step 10 Input “Enter Num”; N
Step 11 A = A + N
Step 12 Input “Press Y to ADD more”; X
Step 13 X = Y GOTO STEP 9 OR GOTO STEP 13
Step 14 Print “Sum =”; A
Step 15 GOTO Step 46
Step 16 N = 2 GOTO STEP 17 or GOTO 25
STEP 17 Input “Enter Num”; N
Output
Desired value
Pavan Sai Kappiri
2024976
[INTERNAL 1]
February 2, 2021
Step 18 S = N
Step 19 Input “Enter Number “; N2
Step 20 Sub= S – N2
Step 21 Input “Press Y to subtract more”; X
Step 22 X = Y GOTO STEP 19 OR GOTO STEP 25
Step 23 Print “Sub=”; Sub
Step 24 GOTO Step 46
Step 25 N=3 GOTO STEP 26 OR GOTO STEP 34
STEP 26 Input “Enter Num”; N
Step 27 M = N
Step 28 Input “Enter Number “; N2
Step 29 M = M * N2
Step 30 Input “Press Y to continue multiply”; X
Step 31 X = Y GOTO STEP 28 OR GOTO STEP 32
Step 32 Print “Value=”; M
Step 33 GOTO STEP 46
Step 34 N = 4 GOTO STEP 35 OR GOTO STEP 40
Step 35 Input “Enter Dividend”; P
STEP 36 Input “Enter Divisor”; Q
Step 37 D= P/ Q
Step 38 Print “Quotient =”; D
Step 39 GOTO STEP 46
Step 40 N = 5 GOTO STEP 41 OR GOTO STEP 46
Step 41 Input “Enter Num1 (Numerator)”; P
STEP 42 Input “Enter Num2 (Denominator)”; Q
Step 43 D= P/ Q
Step 44 P= D*100
Step 45 print” Percentage of the given is=”; P
Step 46 End
Step 5: Testing Algorithm
Sample Selected: - 1
Sample Value: - 10
Sample value 2:-35
Sample Process= 10+35
Sample output= 45
A=0, S=0, M=0, D=0, P=0
A variable for addition, S variable for subtraction, M variable for multiplication, D variable for Division
and P variable for Percentage. As the User selects the arithmetic operation by pressing a digit between 1
to 5, the operation performs after the numbers are entered. Conditional statement If then else end if is
used.
Pavan Sai Kappiri
[INTERNAL 1]
2024976
February 2, 2021
Q 3. Check the given number is Abundant Number or Not.
Step 1
We need an input to enter the number. The number is divided, if the reminder is 0 then the divisor will
be added to total and the process continues until the divisor is greater than the given number.
Step 2
Input: - A Decimal Number
Process: - The number will be divided by X and it increments by 1 until the X is greater than the given
number. Total of the divisors is then calculated and checks if the number is abundant or not.
Output: - Display the results (Statement saying Abundant Number or Not)
Step 3
Input
Decimal Number
Process
Output
The number will be divided by X and it
increments by 1 until the X is greater
than the given number. Total of the
divisors is then calculated and checks if
the number is abundant or not.
Statement saying
Abundant Number or Not
Step 4; Algorithm
Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
Step 7
Step 8
Step 9
Step 10
Step 11
Step 12
Step 13
Step 14
Start
R = 0, X = 0, i = 1, T = 0
Input N
X=X+1
R= N % X
R = 0 GOTO STEP 7 or GOTO step 4
i = i +1
T=T+X
i > N GOTO step 10 or GOTO step 4
Total > N GOTO step 11 Or GOTO step 14
Print “This number is an Abundant Number”
GOTO step 14
Print “This number is not an abundant number”
End
Step 5: Testing Algorithm
Sample Value1: - 10
Sample output Value: - This number is not an abundant number
R, X, I, T variables were initialized. R is
for Reminder. As the number N
entered it is divided by X (Divisor) if the
reminder is 0 then X is added to T, If
reminder is not 0 then x will be
incremented and further divides the
number. At the end T which is the
total of the appropriate divisors is
compared against the given number to
check if the number is abundant or
not.
Pavan Sai Kappiri
[INTERNAL 1]
2024976
February 2, 2021
Q4 Check the given number is Prime or Not.
Step 1
We have to enter a decimal number. It should be divided by the divisor which increments by 1 from 0
until it is > to the given number.
Step 2
Input: - A Decimal Number
Process: - The decimal number will be divided by the divisor(X which increments by 1 from 0 until X
greater than the given number) to take note of the reminder. If the count of reminders which are 0
greater than 2 than it prints it is a prime number or not.
Output: - Statement saying “Prime or Not”
Step 3
Input
Decimal Number
Continuation is On the Next Page
Process
Output
The decimal number will be divided by
the divisor(X which increments by 1
from 0 until X greater than the given
number) to take note of the reminder. If
the numbers of reminder which are 0
are greater than 2 than it prints it is a
prime number or not.
Statement saying “Prime
or Not”
Pavan Sai Kappiri
2024976
[INTERNAL 1]
February 2, 2021
Step 4; PSEUDOCODE
Step 1 BEGIN
Step 2 X  0
Step 3 R  0
Step 4 I  0
Step 5 INPUT “Enter Number”; N
Step 6 WHILE X <= N DO
Step 7 X X + 1
Step 8 R N MOD X
Step 9 IF R = 0 THEN
Step 10 I  I +1
Step 11 End while
Step 12 IF I = 2 THEN
Step 13 OUTPUT “a Prime Number”
Step 14 ELSE
Step 15 OUTPUT “Not a Prime Number”
Step 16 END IF
Step 17 END IF
Step 18 END
Step 5: Testing Algorithm
Sample Value1: - 18
Sample output Value: - Not a Prime number.
R, X, and I variables were initialized. R is for Reminder. I made use of the WHILE Loop for this
problem. The number will be kept on dividing by X and I (reminder is stored) will be
incremented by 1 if the reminder is 0. At the end when X is greater than the given number
while loop stops and displays the results by comparing the variable I to the number 2, If they
are equal then number is said to be prime otherwise it is not prime. The reason for this is that
Prime number is only divisible by 2 numbers which are 1 and the number itself, so, thereby
having reminders more than 2 it means the number is not prime.
Pavan Sai Kappiri
[INTERNAL 1]
2024976
February 2, 2021
Q5 Find the factorial of a given number
Step 1
To find the factorial of the given number, we need an input to enter the number. All the numbers that
are less than given number should be multiplied to find the factorial.
Step 2
Input: - A Decimal Number
Process: - As the number entered, Y will be incremented by 1 and then compared with the given number
if less than or equal to it, then Z will be multiplied with Y, process continues until the condition is not
met.
Output: - Factorial Value
Step 3
Input
Decimal Number
Continuation is On the Next Page
Process
As the number entered, Y will be
incremented by 1 and then compared
with the given number if less than or
equal to it, then Z will be multiplied with
Y, process continues until the condition
is not met.
Output
Factorial Value
Pavan Sai Kappiri
2024976
[INTERNAL 1]
February 2, 2021
Step 4; Flow Chart
START
Y=0
Z=1
Input N
Y=Y+1
Y <= N
YES
Z=Z*Y
NO
Output Z
END
Step 5: Testing Algorithm
Sample Value: - 8
Sample output Value: - 40320
Y and Z were initialized to 0 and 1. When the number is entered, Y will be incremented by 1. Then a decision is
made by comparing Y with the given number, if the condition is true then Z will be multiplied with Y. The
process continues until the condition is false or not true, displaying the output which is a factorial value of the
given number.
Pavan Sai Kappiri
2024976
[INTERNAL 1]
February 2, 2021
End
Download