

C++ Program to Find the Sum of All Digits of a Number
source link: https://www.geeksforgeeks.org/videos/cpp-program-to-find-the-sum-of-all-digits-of-a-number/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

C++ Program to Find the Sum of All Digits of a Number
- 20 Views
- 30/05/2022
In this video, we will see a how-to find Sum of the digits of a given number. Let's understand this concept with the help of examples:
Suppose an Input : n = 123 = 1+2+3 = Output: 6
Now take another example and Input n = 1990 = 1+9+9+0 = Output : 19
General Algorithm for the sum of digits in a given number:
Step 1: Get the number. Step 2: Declare a variable to store the sum and set it to 0. Step 3: Repeat the next two steps till the number is not 0. Step 4: Get the rightmost digit of the number with help of the remainder ‘%’ operator by dividing it by 10 and add it to sum. Step 5: Divide the number by 10 with help of ‘/’ operator to remove the rightmost digit. Step 6: Print or return the sum.
Program for sum of the digits of a given number: https://www.geeksforgeeks.org/program-for-sum-of-the-digits-of-a-given-number/
Recommend
-
30
circle visualization of a number's digits in Go Introduction In the image below, each dot represents a deci...
-
13
How to Find the Sum of All Elements in an Array By Yuvraj Chandra Published 18 hours ago Whether you're using JavaScript, Pytho...
-
9
Problem Code:- FLOW006 Problem Statement:- You're given an integer N. Write a program to calculate the sum of all the digits of N. Input The first line contains an integer T, the tot...
-
5
C++ Program to Find Sum of First 'N' Natural NumbersC++ Program to Find Sum of First 'N' Natural Numbers10 Views22/06/2022In this video, w...
-
8
C++ Program to Find Sum of SequenceSkip to content
-
11
JavaScript Program to Count Digits of a Given NumberSkip to content
-
8
JavaScript Program to Find the Sum of Natural NumbersSkip to content
-
8
JavaScript Program for Sum of Digits of a NumberSkip to content
-
10
PHP Program to Count Digits of a Number ...
-
12
Find First and Last Digits of a Number in PHP ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK