C++ Online Compiler
Example: Sum of Digits of a Number in C++ using While loop
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Sum of Digits of a Number in C++ using While loop #include <iostream> using namespace std; int main() { int x, sum = 0, m; cout << "Enter the integer number::\n"; cin >> x; cout << "The sum of " << x << " digits is = "; while (x > 0) { m = x%10; sum = sum+m; x = x/10; } cout << sum << "\n"; return 0; }
2468
Output
Clear
ADVERTISEMENTS