Sum of Digits of a Five Digit Number Discussions | C | HackerRank

Sum of Digits of a Five Digit Number

Sort by

recency

|

750 Discussions

|

  • + 0 comments

    int main() { int n, sum; scanf("%d", &n); while (n>0) { int temp = n%10; sum+=temp; n/=10; } printf("%d", sum); }

  • + 0 comments

    include

    include

    include

    include

    int main() {

    int n,j,sum=0;
    scanf("%d", &n);
    for (int i=0;i<n;){
        j = n%10;
        n = n/10;
        sum+=j;
    
    }
    printf("%d",sum);
    
    return 0;
    

    }

  • + 0 comments

    Here is Sum of digits of a five digit number solution in c - https://programmingoneonone.com/hackerrank-sum-of-digits-of-a-five-digit-number-solution-in-c.html

  • + 0 comments

    include

    include

    include

    include

    int main() { int n; int sum = 0;

    scanf("%d", &n);
    
    // Loop to calculate the sum of the five digits
    for (int i = 0; i < 5; i++) {
        int remainder = n % 10;
        sum += remainder;
        n /= 10;
    }
    
    printf("%d\n", sum);
    return 0;
    

    }


  • + 0 comments
    #include<stdio.h>
    
    int main()
    {
        int n;
        scanf("%d", &n);
        
        int sum=0;
        
        while(n > 0)
        {
            sum = sum + n % 10;
            
            n = n/10;
        }
        
        printf("%d", sum);
    }