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

Sum of Digits of a Five Digit Number

  • + 0 comments
    int i,n, sumval;
    char value[6];
    scanf("%d", &n);
    
    sprintf(value, "%d", n);
    
    for (i=sumval=0;value[i]!='\0';i++)
        sumval+=value[i]-'0';
    
    printf("%d", sumval);    
    return 0;
    

    }