/* Program for calculating "Sum of Digits" and "Number of Digits" of the Entered number. */ #include<iostream> using namespace std; int main() { int n, a, sum = 0, count = 0; cout << "Enter Number?\t"; cin >> n; while (n != 0) { a = n % 10; sum = sum + a; n = n / 10; count++; } cout << "\nNumber of Digits = " << count << endl; cout << "Sum of Digits = " << sum << endl; return 0; }
This blog is about coding in some commonly used "High Level Languages" like C, C++, Java etc. At first, I will post here basic programs written in C++ language only.
Friday, November 21, 2014
C++ Program for calculating and displaying "Sum of Digits" and "Number of Digits"
Labels:
C++ Programs
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment