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

Sum of Digits of a Five Digit Number

Sort by

recency

|

748 Discussions

|

  • + 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);
    }
    
  • + 0 comments

    int main() {

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

    }

  • + 0 comments

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