diff --git a/C/Program-49/README.md b/C/Program-49/README.md new file mode 100644 index 00000000..7766aa7c --- /dev/null +++ b/C/Program-49/README.md @@ -0,0 +1,8 @@ +Program 49 + +Write a program to find the sum of the digits of the given number. + +Variable description-- +num=Number +sum= Holds the sum +dig=Holds the single digit of the number diff --git a/C/Program-49/program.c b/C/Program-49/program.c new file mode 100644 index 00000000..cc5d2743 --- /dev/null +++ b/C/Program-49/program.c @@ -0,0 +1,18 @@ +#include + +int main() { + + int n; + printf("Enter the number"); + int num; + scanf("%d",&num);//Enter the number + int sum=0,dig=0; + while(num>0) + { + dig=num%10; + sum+=dig; + num/=10; + } + printf("The sum of digits of a number is: %d",sum); + return 0; +}