Skip to main content

Featured

functions in Python

C++ Program to find sum of digits of a decimal number

//Following program adds the digits of a decimal number
#include<iostream.h>
#include<conio.h>


void main()
{
clrscr();
long double a;
cout<<"\nEnter a decimal number\n";
cin>>a;
long d=1;
while(d%10!=0)
{
 a=a*10;
 d=a;
}
d=d/10;
cout<<"\nNumber without decimal is "<<d;
int rem,sum=0;
while(d>0)
{
rem=d%10;
sum=sum+rem;
d=d/10;
}
cout<<"\nSum of All Digits is "<<sum;
getch();
}


OUTPUT:

C++ Program to find sum of digits of a decimal number
 

Comments

  1. Sir this program will not work if the decimal place has a 0, e.g. 123.405

    ReplyDelete

Post a Comment

Popular Posts