Featured
- Get link
- X
- Other Apps
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:
#include<iostream.h>
#include<conio.h>
{
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 |
- Get link
- X
- Other Apps
Labels:
C++ Program to find sum of digits of a decimal number
decimal number digits sum
sum of digits of a decimal number
Comments
Popular Posts
C++ program to display numbers which get reversed after multiplying by 4
- Get link
- X
- Other Apps
Sir this program will not work if the decimal place has a 0, e.g. 123.405
ReplyDeleteYes! That's True! Thanks for your information.
Delete