Sunday, February 8, 2015

Sum of individual digits of a number- Learn

To add individual digits of a given number


#include<iostream.h>
#include<conio.h>
main()
{
            int n, sum=0;
            cout<<”Enter the number.\n”;
            cin>>n;
            while(n!=0)
{
            sum+=n%10;
n/=10;
}
cout<<sum;
getch();
}

Share

& Comment

0 comments:

Post a Comment

 

Copyright © 2015 Code Fervor™ is a registered trademark.

Designed by Templateism By Naman Kumar