1function digSum(n) {
2 let sum = 0;
3 let str = n.toString();
4 console.log(parseInt(str.substring(0, 1)));
5 for (let i = 0; i < str.length; i++) {
6 sum += parseInt(str.substring(i,i+1));
7
8 }
9 return sum;
10}
1num = [int(d) for d in input("Enter the Number:")]
2sum = 0
3for i in range(0, len(num)):
4 sum = sum + num[i]
5
6print("Sum of Digits of a Number: {}".format(sum))
7
8# This code is contributed by Shubhanshu Arya (Prepinsta Placement Cell Student)
1#include <stdio.h>
2
3int getSum(unsigned long long n) {
4 int sum = 0;
5 for (; n; n /= 10)
6 sum += n % 10;
7 return sum;
8}
9
10int main(){
11 printf("Sum of digits = %d\n", getSum(555));
12}