Está en la página 1de 3

Write an algorithm and flowchart for computing the average number of the default 4 numbers.

Algorithm:
start
-----------------------------------------------------
Input A,B,C,D
AVERAGE = (A + B + C + D) / 4
Print AVERAGE
-----------------------------------------------------
end
Flowchart: Program code:
CLS
CLEAR
INPUT a, b, c, d
avr = (a + b + c + d) / 4
PRINT avr
END

Write an algorithm and flowchart for converting length expressed in units of measure 'centimeter' in the measuring
unit 'meter'. Specifies the number of measuring in centimeters, and should determine how it meters.

Algorithm:
start
-----------------------------------------------------
Input X
METER = X / 100
Print METER
-----------------------------------------------------
end
Flowchart: Program code:
CLS
CLEAR
INPUT X
met = X / 100
PRINT met
END

Example V

Write an algorithm and flowchart which a given number A increased 100 times if A is less than 100,
otherwise A is decreased by the 100. Print this result.

Algorithm:
start
-----------------------------------------------------
Input A
If A < 100
Then A = A × 100
Else A = A - 100
Print A
-----------------------------------------------------
end
Flowchart: Program code:
CLS
CLEAR
INPUT A
IF A < 100 THEN
A = A * 100
ELSE
A = A - 100
END IF
PRINT A
END

Example IX

Write an algorithm and flowchart for the addition of the first N integers.

Algorithm:
start
-----------------------------------------------------
X=0
SUM = 0
Input N
X = X + 1
SUM = SUM + X
If X < N
Then go back to 'X = X + 1'
Print SUM
-----------------------------------------------------
end
Flowchart: Program code:
10 CLS
20 CLEAR
30 X = 0: sum = 0
40 INPUT "Input limit of aggregate:"; N
DO
X = X + 1
sum = sum + X
LOOP WHILE X < N
REM Using 'LOOP UNTIL' at first
REM complied the condition
REM goes out of the loop
50 PRINT "Sum is:"; sum
60 END
--------------------------------------------
10 CLS
20 CLEAR
30 x = 0: sum = 0
40 INPUT "Input limit of aggregate:"; N
FOR i = 1 TO N STEP 1
x = x + 1
sum = sum + x
NEXT i
50 PRINT "Sum is:"; sum
60 END
-------------------------------------------
Example X

Write an algorithm and flowchart that loads N integers. Calculate the sum of all positive and the sum of
all negative numbers.

Algorithm:
start
-----------------------------------------------------
Input N
number = 0
positive = 0
negative = 0
Input X
If X > 0
Then positive = positive + X
Else negative = negative + x
number = number + 1
If number < N
Then go back to 'Input X'
Print positive, negative
-----------------------------------------------------
end
Flowchart: Program code:

10 CLS
20 CLEAR
30 number = 0: positive = 0: negative = 0
40 INPUT "Input limit of aggregate:"; N
DO
INPUT "Input No smaller of limit:"; X
IF X > 0 THEN
positive = positive + X
ELSE
negative = negative + X
END IF
number = number + 1
LOOP WHILE X < N
REM Using 'LOOP UNTIL' at first
REM complied the condition
REM goes out of the loop
50 PRINT "Sum of positive is:"; positive
60 PRINT "Sum of negative is:"; negative
70 END

También podría gustarte