---
title: "Algorithm for numbers divisible by 9 not 6"
subject: "Computer Programming"
chapter: 2
key: "semester_1/computer_programming:algo-flowchart-divisible-9-not-6"
source: https://www.bctengineer.com/q/semester_1/computer_programming/algo-flowchart-divisible-9-not-6
site: BCT Engineering
---

# Algorithm for numbers divisible by 9 not 6

Computer Programming · Chapter 2: Problem solving using Computer

- Asked in: 2067 Asoj, 5+5 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/algo-flowchart-divisible-9-not-6
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-2

## Question

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.

## 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.

## Answer

**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
1. Start
2. Set `total = 0`, `count = 0`, `sum = 0`
3. Read `input`
4. If `input = NO`: if `total >= 50` go to step 8, otherwise print "Enter at least 50 numbers" and go to step 3
5. Convert `input` to the integer `n` and set `total = total + 1`
6. If `n >= 1` and `n <= 100` and `n mod 9 = 0` and `n mod 6 != 0`, then set `sum = sum + n` and `count = count + 1`
7. Go to step 3
8. If `count = 0`, print "No such number was entered"
9. Otherwise calculate `avg = sum / count` and print `sum` and `avg`
10. Stop

#### Flowchart
Part 1: reading and testing the numbers

```text
        ( 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

```text
    (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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which number qualifies?
   A. 18
   B. 27
   C. 54
   D. 36
   Answer: B. 27 is divisible by 9 but not by 6. (Key point: Qualifying numbers)

2. NO is accepted only when
   A. any number is entered
   B. count > 0
   C. at least 50 numbers have been entered
   D. sum > 100
   Answer: C. Otherwise it asks for more. (Key point: Reading rule)

3. If count = 0 the system
   A. divides by zero
   B. prints average 0
   C. stops silently
   D. displays a message that no such number was entered
   Answer: D. Avoids division by zero. (Key point: No qualifier)

4. Numbers 9, 27, 45 give average
   A. 27
   B. 81
   C. 3
   D. 45
   Answer: A. 81/3 = 27. (Key point: Example)

## Related in Computer Programming

- [Sum and average until 0 is entered](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asum-average-until-zero) — Computer Programming, chapter 5
- [Read records until end; show nth record](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-worker-nth-record) — Computer Programming, chapter 10, asked 2×
- [Sum and average between M and N using pointer](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apointer-sum-average-range) — Computer Programming, chapter 9
- [Sum of digits until single digit](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adigit-sum-single-digit) — Computer Programming, chapter 5, asked 2×
- [Function definition; sum of two numbers](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afunction-definition-sum-two) — Computer Programming, chapter 6
- [Odd and even numbers to separate files](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-odd-even-until-no) — Computer Programming, chapter 10, asked 2×

## Related in other subjects

- [C program: sum of two 8-bit BCD numbers](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-bcd-sum-c) — Embedded System, chapter 9
- [8086 ALP: sum of 100 even numbers](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-sum-even-numbers) — Microprocessor, chapter 3
- [Function template: sum and average of array](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afunction-template-sum-average) — Object Oriented Programming, chapter 9
- [Elements of communication system; modulation is a must](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Acomm-elements-modulation-justify) — Communication Systems, chapter 1
