Вы находитесь на странице: 1из 37

SAMPLE

FLOWCHARTS

Question 1
Draw the program flowchart for finding the
sum of first 100 odd numbers.

Since we have to find sum of odd numbers it should


start from 1. So, our variable should be set as 1
Increment of the variable shall be by 2
The last no the series shall be 199. So we shall check
out counter at 199.

Solution 1
Start
Clear all working
Locations

Set A=1
B = B+A
A = A+2

No

?
A=
199

Yes

Print B
Stop

Step 4:
Since we have to stop at the 100th
terms which
is equal
to 199,
Step
0:
step
4 poses
a question.
Has A
Use
START
to start
a flowchart
1 :go back to step
become 199 ?Step
If not,
All working
locations
are
set at
zero.
3 by forming
loop.
Thus,
A is
This
is necessary
because
repeatedly
incremented
in stepif 5they
and
areadded
holding
some
of the
the
to B inStep
step2:3.data
B holds
A is set atprogram,
1sum
so that
subsequently
by
previous
that
is liable
cumulative
upto
thedata
latest
terms
incrementing
it successively
by199
2,
toheld
corrupt
result
of the
flowchart.
in A.the
When
A has
become
wethat
get means
the wanted
odd terms :
the necessary
Step
3:
1,3,5,7
computations
have etc.
been
carried out
Asoisthat
poured
into6Bthe
i.e.,
added
to B. B
in step
result
is printed.
being 0 at the moment and A being
1, B becomes
0 + 1 = 1.
Step 5:
we shall increment A by 2. So that
although at the moment A is 1, it will
be made 3 in step 5 , and so on.
Step 6 :
Result is Printed

Question 2
There are three quantities; Q1 Q2 and Q3. It is desired to
obtain the highest of these in location H and lowest of
these in location L.

Since we have to obtain highest and lowest of 3


categories, we will check 2 at a time and compare it with
third quantity i.e. we shall compare the highest and
lowest of the 2 with the 3rd
Highest and lowest values shall change only if 3rd is
higher than highest or lower than lowest.
So effectively we shall have 3 decision boxes in the
program. To compare 2 and than compare 3rd with
highest and with lowest.

Solution 2
Step 0
All working locations are
assigned
Step 2toZero
Any two quantities, say Q1 and
Q2 are compared. If Q1 is
greater than Q2.

Start
Clear all working
Locations
Read Q1,
Q2 and Q3
Yes

?
Q1 > Q2

No

H = Q1

H = Q2

L = Q2

L = Q1

Step 1
The three quantities Q1,
Q2 and Q3 are read in via,
say, these values are
entered
through
keyboard
a
Steps
3B andof4B
terminal.
Alternatively
we can make H =
Q1 and L = Q2 in
Steps 3A and 4A,
we make H = Q2 and L = Q1.

No

?
Q3 < L

?
Q3 > H

Yes

No

H = Q3

Step 5,
we are holding the
higher of Q1 and Q2 in H
and the lower of these in
L. We see if Q3 is
greater than H.

Yes

L = Q3

Step 8
If its a Yes, H is made
equal to Q3.

Stop

Step 6
If Q3 is not greater than
H, we compare Q3 with
L 7
Step
if Q3 < L, we make L =
Q3, otherwise, the job
has already been
done prior to Step 5.

Question 3
Draw the flowchart for deriving the sum of the
squares of first 20 odd numbers.

Since we want to calculate sum of 20 odd nos, our


variable shall start from 1.
Increment in the variable shall be of 2 units
When we accumulate value in another variable, care
should be taken that we add the sum of the number and
not original no.
The last no shall be 39. So we have to check counter /
variable upto 39. So we will have only 1 decision box.

Solution 3

Start
Clear all Working
Locations
Set K = 1
Square = K * K
C =C + Square
K=K+
2

No

?
K = 39
PRINT
C
END

Yes

Step 0
All working locations
are assigned the value
Step 1
zero
The first odd number
is 1 soStep
we set
2 K=1
The square of first odd
number is computed
by multiplying K with K
and the result so
obtained is stored in
Step
3
location
SQUARE.
We accumulate the
4
first termStep
i.e. square
of
The
20th
odd
number
the first odd number 1is
39, therefore
in this
in location
C. step
we see if K has become 39
5
or notStep
(by step
5)
K is increment by 2 i.e.
it becomes 1+2 = 3

Question 4
The weights of newly born babies in a hospital are input to
computer. The hospital in charge is interested to find the
maximum, minimum and mean weights of all the weights
of the babies. Draw a suitable flow chart for his problem. A
value of zero can be used at the end of the list of baby
weights. This denotes the end of the list.

We have to calculate Minimum, maximum and mean


weights. So we have to define 5 variables as follows
Minimum
Maximum
Total
Count
Mean (Total / Count)
Take care that Mean weight can be derived only after
we have checked all the weights for minimum /
maximum and added it to Total Weight and not at each
step.

We shall define first weight as Minimum, Maximum and


Total and keep comparing each variable to check if its
less than minimum or more than maximum, and than we
shall add it to total. Also count shall be increased by 1
for every number checked.
Since question says last weight is 0, we shall check if
we have reached at weight = 0, once we reach there we
shall calculate Mean and Stop. Till than the Loop shall
keep running. So effectively we shall have 3 decision
boxes same as last ques.

Solution 4
START
INPUT W
MINW = W
MAXW = W
TOTW = W
COUNT = 1

INPUT W

IS
W=0?

Yes

MEANW=TOTW/C
OUNT
PRINT
MAXW, MINW,
MEANW

No

IS
W<
MINW
?

Yes

MINW=W
END

No

IS
W>
MAXW
?

Solution 4 (2)

Yes

No

TOTW=TOTW W
COUNT=COUNT + 1

MAXW=W

Question 5 (On computing Customs Duties)


Assume that imported goods from foreign
countries are classified into 4 categories for the
purpose of levying customs duty. The rate for each
category is as follows :
Class No.
(K)

Class of Goods

Customs duty (%), on


Values of Goods (V)

1
2
3
4

Foods, beverages
Clothing, footwear
Heavy machinery
Luxury items

10
15
17.5
40

Draw the flowchart for computing the appropriate


customs duty.

We shall use following variable


Value
Rate of Duty
Class
There are broadly 4 classes defined in the question.
Since these classes are exhaustive, we need to check
only for 3 classes, If it does not fit in 3 classes it has to
be in the 4th class. So we shall have 3 decision boxes

START

Solution 5

Input Value,
Class no, V, K
No

?
K=1
Yes

?
K=2
Yes

DUTY =
V * 0.1

No

No

?
K=3

DUTY =
V * 0.4

Yes

DUTY =
V * 0.15
DUTY =
V * 0.175

Print
DUTY
Last
Item?
No

Yes

END

Question 6
A bicycle shop in Delhi hires bicycles by the day at different
rates as shown in the following table :Season

Charges per day (in Rs.)

Spring (March - May)

8.00

Summer (June - August)

9.50

Autumn (Sept - Nov.)

5.00

Winter (Dec. - Feb.)

6.00

To attract his customers, the proprietor also gives a


discount on the number of days a bicycle is hired for. If the
hire period is more than 10 days, a reduction of 15% is
made. For every bicycle hired, a deposit of Rs 20 must be
paid. Develop a flowchart to print out the details for each
customer such as name of customer, number of days a
bicycle is hired for, hire-charges and total charges
including the deposit. It is also assumed that there are 25
customers and complete details for each customer such as
name of customer, season and number of days the bicycle
is required for is inputted through console.

We shall define/ read following variables


Name
Counter
Season
No of Days
Rate
Net Rate (After Discount)
Hire Charges ( net Rate * No of Days)
Total Hire charges ( Hire Charges + Rs.20)

We shall check the season first because firstly there are


4 seasons that need to checked and also, to calculate
discount (outcome for no of days condition) we need the
rate of bicycle. Rate can be derived only from Season
details and so we check season first.
Following points need to be checked for every bicycle.
Season (4 Conditions)
No of Days Hired for (1 Condition)
Last record (1 condition)
Thus we shall have 6 condition Boxes
Do not forget to add Rs.20 in total Hire charges

START

Solution 6

Clear all working locations


A
Read NAME,
SEAS, DAYS
N=N+1
SEAS =
Spring

Yes

RATE = 8.00

No

SEAS =
Summer

Yes

RATE = 9.50

No

SEAS =
Autumn
No

RATE = 5.00
Yes

SEAS =
Winter
No

Yes

RATE = 6.00

Solution 6 (2)
Yes

Print
Invalid Seas

DAY >10

NRT= RATERATE * 0.15

No

NRT = Rate
B
HCHG = Days * NRT
TCHG = HCHG +20.00
No

N >=25
Yes

END

Print
NAME, DAYS,
HCHG, TCHG

In the Next flowchart ,comparison step is initialized and modified for


looping. The following is the comprehensive list of comparisons of this
type that are valid:
J(X) > K(Y)
J(X) = K(Y)
J(X) K(Y)
J(X) < K(Y)

Question 7
Prices for ten commodities in the current year are
designated by J(X), X varying from 1 to 10. Likewise,
their last years prices are designated by K(Y), Y
varying from 1 to 10. Draw the flowchart for finding the
number, N of commodities of which prices have
increased.

In array problems, always remember that we shall


check the counter upto the no of slots in that array.
Always initiate the position of the cursor in the array i.e.
we have set X and Y as 0.
Use only the functions that are permitted to be used in
the array.

Solution 7

START
Clear all working locations
Set X = 0
Set Y = 0
Increment X by 1
Increment Y by 1
No

?
No

X=10
Yes

Print N

END

?
J (X)>
K(Y)

Yes

N=N+1

Question 8
Add 45 (a constant) to the wages of 10 persons
designated by J(X), X = 1,2...10

In array problems, always remember that we shall


check the counter upto the no of slots in that array.
Always initiate the position of the cursor in the array i.e.
we have set X as 0.
Use only the functions that are permitted to be used in
the array.

Solution 8
START
Clear all working locations
Set X = 0
Increment X by 1
J (X) = J(X) + 45
No

?
X=10
Yes

END

Question 9
Print 6 Ps in the pattern given below
012(print position)
p
p
p
p
p
p
007 (print position)

In Print problems we always have to define the position


at which we want to print the material.
The material that needs to be print has to be put in
either commas () or is defined in a variable.
1 Line CS feed function is generally used in Print
problems.

Solution 9
START
Clear all working locations
Set Y = 13
Decrement Y by 1
1 Line CS Feed
Print P at Y

No

?
Y=7
Yes

END

Question 10
In locations J(X), X = 1, 2....200 are held 200 quantities.
Draw flowchart for finding the ratio of the total number
of quantities indivisible by 10 to that of divisible by 10.

Solution:
The following symbols are used in it.
NONTEN
Total number of items not divisible by 10
TENNER
Total number of items divisible by 10
RATIO
Ratio NONTEN/TENNER
J(X), X = 1,2...200 are used to hold the last digit of a quantity.
Partial transfer (as we have down in this flowchart) of one or more
consecutive digits from one location into another location is valid.

When checking whether a no is divisible by other no or


not, use standard divisibility tests. Like divisibility test for
the no 5 is that last digit should be o or 5. Similarly for
no 10 it is that last digit should be 0.
Always keep in mind the things that question asks u to
calculate. Define variable for each of the item that is
asked.
Counter shall go upto the number of slots in the array.
2 Decision boxes shall be prepared, one to check
divisibility and other for counter .

START

Solution 10

Set X = 0
Increment X by 1
Transfer last digit of
J(X) in J
No

Yes

J=0

Increment
NONTEN by 1
No

Increment
TENNER by 1
?
X=200

Yes

RATIO = NONTEN / TENNER


Print RATIO
END

Вам также может понравиться