Wednesday, October 11, 2017

How to calculate sum of all digit of a given integer in c++ programming language

Here is the code for calculate sum of all digit and length of  a given integer in c++ programming.

If you have any problem to understand the code please put your question into the comment below .

 #include<bits/stdc++.h>
using namespace std;
int main()
{
    int num;
    int sum = 0, count=0;

    cout << " Enter a number : ";
    cin >> num;
    while ( num > 0 )
    {
        sum += num % 10;
        num /= 10;
        count++;
    }
    cout<< "The given integer is = " << num <<endl;
    cout << "The sum all digit is = " << sum << endl;
    cout << "The length of the given integer is = " << count <<endl;

    return 0;
}

No comments:

Post a Comment

কম্পিউটার প্রোগ্রামিং শেখা কতটা গুরুত্বপূর্ণ ?

প্রোগ্রামিং কতটা গুরুত্বপূর্ণ? কম্পিউটার বিজ্ঞানের অনেক বড় একটা অংশ জুড়েই রয়েছে প্রোগ্রামিংয়ের দখল। প্রোগ্রামিং ছাড়া আমর...