This program find sum of the digits entered number.The idea is slice the every digits from number and then sum of digits.
Example :
Example :
- Assume Entered number is : 789
- Now slice the given number : 9 , 8 ,7.
- Sum of the digits is : 9+8+7=24.
Sum Of Digits :
Program :
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
do{
long int n,i,s=0 ,r;
clrscr();
printf("\n\tEnter Number(1-999999999):");
scanf("%ld",&n);
if(n>=1 || n<=999999999)
{
while(n>=1)
{
r=n%10;
s=s+r;
n=n/10;
}
}
printf("\n\t Sum of digit:<%d>",s);
printf("\n\t Continue(y/n):");
ch=getch();
}while(ch=='y'||ch=='Y');
getch();
}
If you have any Further Information and Quires about this Article don't hesitate to comment in comment box below.
AND
If you like this article , like our Facebook like page and click +1 to support 123techguide
|