C++ program to find the sum of all integer between 100 and 200 which are divisible by 9.

By Prof. Fazal Rehman Shamil
Last modified on November 21st, 2020

Write a C++ program to find the number and sum of all integer between 100 and 200 which are divisible by 9.

Flowchart of the program to find the number and sum of all integer which are divisible by 9

C++ program to find the sum of all integer between 100 and 200 which are divisible by 9.

Source code in C++

Output

Please enter numbers between 100 & 130 which are divisible by 9:

number divisible by 9 is: 108

number divisible by 9 is : 117

number divisible by 9 is: 126

the sum of all numbers divisible by 9 is: 351

 

Excercise

Find the possible mistakes in the following Shamil’s Flow Table of the program to find the number and sum of all integer which are divisible by 9.

Loop If condition Lines will Be Executed Actual work to do
i=101 False 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 16, 17, 8
i=102 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 2 times, 8
i=103 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 3 times, 8
i=104 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 4 times, 8
i=105 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 5 times, 8
i=106 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 6 times, 8
i=107 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7 times, 8
i=108 True 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 8 Sum=sum+i

Sum=0+108

Sum=108

i=109 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 8, 9, 10, 15, 16, 17, 8
i=110 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 2 times, 8
i=111 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 3 times, 8
i=112 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 4 times, 8
i=113 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 5 times, 8
i=114 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 6 times, 8
i=115 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 7 times, 8
i=116 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8 times, 8
i=117 True 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8 times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 8 Sum=sum+i

Sum=108+117

Sum=225

i=118 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 8, 9, 10, 15, 16, 17, 8
i=119 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8 times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 2 times, 8
i=120 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8 times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 3 times, 8
i=121 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8 times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 4times, 8
i=122 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8 times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 5 times, 8
i=123 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8 times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 6 times, 8
i=124 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8 times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 7 times, 8
i=125 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8 times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8 times, 8
i=126 True 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 8 Sum=sum+i

Sum=225+126

Sum=351

i=127 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 8, 9, 10, 15, 16, 17, 8
i=128 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 2times, 8
i=129 False 1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 3times, 8
i=130

loop terminates

1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 15, 16, 17) 7times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 8times, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, (8, 9, 10, 15, 16, 17) 4times, 18, 19 Sum of all numbers divisible by 9=351
Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.