diff --git a/Sum_of_digits.txt b/Sum_of_digits.txt new file mode 100644 index 0000000..f69ad6d --- /dev/null +++ b/Sum_of_digits.txt @@ -0,0 +1,22 @@ +/* Description of the code +This code provides the sum of digits of a given number. +eg:if the entered number is 234, the the sum of digits will be: +sum=2+3+4=9 +so the desired output will be 9. +*/ + +#include +int main() +{ + int n,r,sum=0; + printf("Accept the number: "); + scanf("%d",&n); + while(n!=0) + { + r=n%10; + sum=sum+r; + n=n/10; + } + printf("Sum of number %d",sum); + return 0; +} \ No newline at end of file