From 1100eafaef6ff16e8f943395a856e9174c512a0b Mon Sep 17 00:00:00 2001 From: ferdyfebriyanto Date: Wed, 26 Oct 2022 11:59:35 +0700 Subject: [PATCH] Add C Program --- sum-of-digits.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 sum-of-digits.c diff --git a/sum-of-digits.c b/sum-of-digits.c new file mode 100644 index 0000000..c5006e8 --- /dev/null +++ b/sum-of-digits.c @@ -0,0 +1,15 @@ +#include +int main() +{ + int n, sum = 0, m; + printf("Enter a number:"); + scanf("%d", &n); + while (n > 0) + { + m = n % 10; + sum = sum + m; + n = n / 10; + } + printf("Sum is=%d", sum); + return 0; +} \ No newline at end of file