/*Write a C++ program to find sum of digits in a given number */
#include<iostream.h>
#include<conio.h>
void main( )
{
int n,sum=0,digit;
clrscr( );
cout<<"Enter the Number: ";
cin>>n;
while(n!=0)
{
digit=n%10;
sum=sum+digit;
n=n/10;
}
cout<<"Sum of the digits is "<<sum;
getch( );
}

No comments: