DESCRIPTION-:THIS PROGRAM FINDS THE SUM OF THE DIGITS
OF THE ENTERED NUMBER.
FOR EXAMPLE IF WE HAVE NUMBER 123
THEN SUM=1+2+3=6.
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,rem,sum=0;
cout<<"enter the value of n";
cin>>n;
while(n>0)
{
rem=n%10;
n=n/10;
sum=sum+rem;
}
cout<<"sum of digit is"<<sum;
getch();
}
OF THE ENTERED NUMBER.
FOR EXAMPLE IF WE HAVE NUMBER 123
THEN SUM=1+2+3=6.
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,rem,sum=0;
cout<<"enter the value of n";
cin>>n;
while(n>0)
{
rem=n%10;
n=n/10;
sum=sum+rem;
}
cout<<"sum of digit is"<<sum;
getch();
}
0 comments:
Post a Comment