Program to find “SUM OF DIGITS of a given number” using while loop.

source code:

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
  int number,r,rev=0;
  cout<<"Enter a number to find sum of its digits : ";
  cin>>number;cout<<endl;
  while(number>0)
     {
        r=number%10;
        rev=rev*10+r;
        number=number/10;
      }
  
  cout<<"Reverse is "<<rev;
  getch();
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s