0
i want to know how to add the digits of an integer in c++ program??
in which user give us an integer and the program will add the digits of that given integer!!
1 Resposta
+ 3
#include <iostream>
using namespace std;
int main() {
int n;
int sum =0;
cout<<"enter an integer "<<endl;
cin>>n;
while(n != 0){
sum = sum + (n % 10);
n = n/10;
}
cout<<"sum of digits is :";
cout<<sum;
return 0;
}