Question

58 views
Skip to first unread message

Ayubu Zuberi

unread,
Feb 3, 2023, 9:18:03 AM2/3/23
to C++ GCU Forum
Write an algorithm in pseudocode for a program to find the sum of digits of a given number

103 Md Fayez Anwar

unread,
Feb 4, 2023, 7:40:12 AM2/4/23
to C++ GCU Forum
1. Take as input the given number in a variable, say N
2. Create another variable to store the sum of digits, say S and initialize it to 0
3. Add the value of (N%10) to S, i.e. S = S + (N%10)
4. Update N as, N = N/10
5. If N is greater than 0, go to step 2. Otherwise, go to step 6.
6. Output S, the required sum of digits.

103 Md Fayez Anwar

unread,
Feb 4, 2023, 7:42:00 AM2/4/23
to C++ GCU Forum
A typo in Step 5, it should 5. If N is greater than 0, go to step 3. Otherwise, go to step 6.
Reply all
Reply to author
Forward
0 new messages