.
Home About-us Privacy Policy Contact-us Services

Wednesday, October 7, 2015

C++ Program to find Sum of the digits given a number

ad+1

In this Program example user can enter the digit and display the sum of in output.

Program -


#include<iostream.h>
#include<conio.h>
void main()
{
int a,d,sum=0;
clrscr();
cout<<"\n enter the number:";
cin>>a;
while(a>0)
{
d=a%10;
a/=10;
sum+=d;
}
cout<<"sum="<<sum;
getch();
}

Output - 


enter the number:234
sum=9



0 comments:

Post a Comment

Home About-us Privacy Policy Contact-us Services
Copyright © 2014 All Programs Examples | All Rights Reserved. Blogger Templates Download Blogger Templates