I-78 Computer Fundamentals
Step 3: Read n
Step 4: While i <= n
Read num
Add num to sum
Increment i by 1
End while
Step 5: Calculate Average = Sum / n
Step 6: Display Average
Step 7: Stop
26. Write an algorithm to generate a Fibonacci series.
Ans:
Step 1: Start
Step 2: Initialize sum=0, A=0, B=1, i=3
Step 3: Read the number of terms you want in the Fibonacci
series, say n
Step 4: Display A, B
Step 5: While i <= n
Add A and B and store value in sum
Display sum
Assign the value of B to A, that is, A=B
Assign the value of sum to B, that is, B=sum
Increment i by 1
End while
Step 6: Stop
27. Write an algorithm to test whether the given number is prime or not.
Ans:
Step 1: Start
Step 2: Read num
Step 3: Initialize div = 2
Step 4: Calculate half = num/2
Step 5: While (div <= half)
Divide num by div and store remainder in rem
If rem = 0 then
Display given number is not prime
Go to Step 7
End if
Increment div by 1
End while
Step 6: Display given number is prime
Step 7: Stop
M04_ITL-ESL4791_01_SE_C04.indd 78 12/22/2012 4:53:50 PM
Computer Software and Programming I-79
28. Draw a flowchart to check whether a given number is odd or even.
Ans: The flowchart to check whether a number is even or odd is shown here.
Start
Read Num
No Yes
If
(Num mod 2) = 0
Stop
Print
“Number is odd”
Print
“Number is even”
29. Draw a flowchart to compute sum of n natural numbers.
Ans: The flowchart to compute the sum of n natural numbers is shown here.
Start
Read N
Count = 1
Sum = 0
If
Count <= N
Print Sum
Stop
No
Yes
Count = Count + 1
Sum = Sum + Count
M04_ITL-ESL4791_01_SE_C04.indd 79 12/22/2012 4:53:51 PM
I-80 Computer Fundamentals
30. Draw a flowchart to compute the factorial of a number.
Ans: The flowchart to compute the factorial of a number is shown here.
Start
Read Num
Fact = 1
If
Num > 0
Print Fact
Stop
No
Yes
Num = Num 1
Fact = Fact * Num
31. Draw a flowchart to solve a given quadratic equation for all possible cases.
Ans: The flowchart to find the roots of a quadratic equation is shown here.
Start
Input coefficients
a, b and c
Set D = b
2
4 * a * c
Is
D
> 0< 0
= 0
Root1 = Root2 =
2 * a
b
Set real =
2 * a
b
Set imag =
2 * a
D
Set Root1 =
2 * a
(−b + )
D
Print “Real Roots:”
Root1, Root2
Print “Equal Roots:”
Root1
Stop
Print “Imaginary
Roots:” Root1, Root2
Root 1 = real + i imag
Root 2 = real i imag
Set Root2 =
2 * a
(−b − )
D
M04_ITL-ESL4791_01_SE_C04.indd 80 12/22/2012 4:53:51 PM
Computer Software and Programming I-81
32. Draw a flowchart to test whether a given number is prime or not.
Ans: The flowchart to check whether a number is prime or not is shown here.
Start
Read num
div = 2
half = num/2
Is
div < = half?
Is
rem = 0?
Yes
No
No
Yes
rem = num % div
div = div + 1
Print “Number
is prime”
Print “Number
not prime”
Stop
33. Draw a flowchart to compute the salary of an employee in a company. Assume that there 
are two types of employees in the company: daily wages and regular. Salary is calculated 
as number of hours worked * wages/hour for daily wages and basic pay +(% of DA * 
basic pay)/100 +HRA +MA for a regular employee.  Sketch the flow of your design for 
regular employee with basic pay = 5000, % of DA = 75% and HRA = 500.
Ans: The flowchart to compute the salary of an employee in a company is shown here.
M04_ITL-ESL4791_01_SE_C04.indd 81 12/22/2012 4:53:52 PM
I-82 Computer Fundamentals
Start
Input type
of employee
Is
regular
employee?
Input basic pay and
percentage of
DA, HRA, MA
Set DA =
(Percentage of
DA * basic pay) / 100
Set sal = basic
pay + DA + HRA + MA
Print sal
Stop
YesNo
Input number of hours
worked and
wages per hour
Set sal = number of
hours worked * wages
per hour
Steps to calculate the salary of regular employee when basic pay = 5000, % of DA = 75% and
HRA = 500:
1. Start
2. The regular employee is input.
3. Its basic pay (5000), percentage of DA (75%), HRA (500) and MA (0) is input.
4. Then DA is calculated in the following manner:
DA = (75 * 5000) / 100
= 3750
5. Sal = 5000 + 3750 + 500 + 0
= 9250
M04_ITL-ESL4791_01_SE_C04.indd 82 12/22/2012 4:53:52 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset