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;
}
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