hi,
i think this would solve your question.
#include<iostream.h>
void main()
{
long int num=123456; int sum=0;
for(;num>0;sum+=num%10,num/=10);
cout<<sum;
}
// answer would be there in the variable sum
but if you want find sum of digits for numbers with more no of digits long int storage would not be sufficient.
Thanks,
Matrix
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
To unsubscribe : [EMAIL PROTECTED]
| Yahoo! Groups Sponsor | |
|
|
Yahoo! Groups Links
- To reply to this message, go to:
http://groups.yahoo.com/group/Programmers-Town/post?act=reply&messageNum=4950
Please do not reply to this message via email. (more info)
- To visit your group on the web, go to:
http://groups.yahoo.com/group/Programmers-Town/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
