- 2067 Asoj · 5+5 marks
Algorithm for numbers divisible by 9 not 6
Short answer
Read numbers until user enters NO after at least 50 entries. For each integer in 1–100 exactly divisible by 9 but not by 6, accumulate sum and count. After input, if count > 0 compute average = sum/count; else display no‑such‑number message.
You are given a task to develop a system to read at least 50 integer numbers and continue until the user enters NO. Your system must have capacity to calculate the sum and average of those numbers which are exactly divisible by 9 but not by 6 and lies in between 1 to 100 and display a suitable message if no such number is read. Write algorithm and flowchart to develop such system.
Assumptions: numbers are read as text so that the word NO can be detected; at least 50 numbers must be entered before NO is accepted; a number qualifies if it is between 1 and 100, divisible by 9 and not divisible by 6 (these are 9, 27, 45, 63, 81, 99).
Variables: total (numbers read), count (qualifying numbers), sum.
Algorithm
- Start
- Set
total = 0,count = 0,sum = 0 - Read
input - If
input = NO: iftotal >= 50go to step 8, otherwise print "Enter at least 50 numbers" and go to step 3 - Convert
inputto the integernand settotal = total + 1 - If
n >= 1andn <= 100andn mod 9 = 0andn mod 6 != 0, then setsum = sum + nandcount = count + 1 - Go to step 3
- If
count = 0, print "No such number was entered" - Otherwise calculate
avg = sum / countand printsumandavg - Stop
Flowchart
Part 1: reading and testing the numbers
( Start )
|
[ total=0, count=0, sum=0 ]
|
+----->|<-----------------+ (B)
| v |
| / Read input / |
| | |
| < input = NO ? >--Yes--> (A)
| | No
| [ n = integer(input) ]
| [ total = total + 1 ]
| |
| < n>=1, n<=100, n%9=0, n%6!=0 ? >
| No | | Yes
| | [ sum = sum + n ]
| | [ count = count + 1 ]
+-------+------------+
Part 2: after NO is entered
(A)
|
< total >= 50 ? >--No--> / Print "Enter at least 50" /
| Yes |
| (B) back to Read input
< count = 0 ? >--Yes--> / Print "No such number" /
| No |
[ avg = sum / count ] |
/ Print sum, avg / |
| |
+-------------+----------------+
|
( Stop )
Example: if the qualifying numbers entered are 9, 27 and 45, then sum = 81, count = 3 and average = 27.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Sum and average until 0 is entered · Computer Programming, chapter 5
- Read records until end; show nth record · Computer Programming, chapter 10 · asked 2×
- Sum and average between M and N using pointer · Computer Programming, chapter 9
- Sum of digits until single digit · Computer Programming, chapter 5 · asked 2×
- Function definition; sum of two numbers · Computer Programming, chapter 6
- Odd and even numbers to separate files · Computer Programming, chapter 10 · asked 2×
- C program: sum of two 8-bit BCD numbers · Embedded System, chapter 9
- 8086 ALP: sum of 100 even numbers · Microprocessor, chapter 3
- Function template: sum and average of array · Object Oriented Programming, chapter 9
- Elements of communication system; modulation is a must · Communication Systems, chapter 1