C++ Program to Find Sum of Digits of a Number – C++ Program

By Prof. Fazal Rehman Shamil
Last modified on February 14th, 2020

C++ Program to Find the Sum of Digits of a Number – C++ Program.

Flowchart of  Sum of Digits of a Number – C++

Flowchart of Program to Find Sum of Digits of a Number - C++ Program

 

C++ Source Code of Program

Output

Please Enter a number: 5

The sum of series = 111105

Excercise

Find the possible mistakes in the following Shamil’s Flow Table of the Program to Find the Sum of Digits of a Number – C++ Program.

Loop condition What lines will execute Actual work to do
 

i=1

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 sum=sum +k;

9=0+9

K=k*10+9;

99=9*10+9

1 time

i=2

True

 

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

10,11,12,13,14,15,16

sum=sum +k;

108=9+99

K=k*10+9;

999=99*10+9

2 times

i=3

True

 

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

10,11,12,13,14,15,16,10,11,12,13,14,15,16

sum=sum +k;

1107=108+999

K=k*10+9;

9999=999*10+9

3 time

i=4

False 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

10,11,12,13,14,15,16,10,11,12,13,14,15,16,17,18

 

“sum of series”

 

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.