write a program to find sum of digits of a number

A number is taken from user and the sum of the digits is displayed.


Select To use this code as it is.. select and copy paste this code into code.cpp file :)



  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n,sum=0,m;
  7. cout<<"please enter a five digit no.: ";
  8. cin>>n;
  9. while(n>0)
  10. //Coding by: Snehil Khanor
  11. //http://WapCPP.blogspot.com
  12. {
  13. m=n%10;
  14. sum=sum+m;
  15. n=n/10;
  16. }
  17. cout<<sum;
  18. getch();
  19. }

Check out this stream