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!!

9th Nov 2016, 4:18 AM
Usama Ali
Usama Ali - avatar
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; }
9th Nov 2016, 4:34 AM
kamal joshi
kamal joshi - avatar