HackerRank C- Sum of Digits of a Five Digit Number

In this challenge, you have to input a five digit number and print the sum of digits of the number.

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. int main() {
  6. int n,sum=0,i;
  7. scanf("%d", &n);
  8. for(i=n;i!=0;i=i/10)
  9. {
  10. sum=sum+(i%10);
  11. }
  12. printf("%d",sum);
  13. return 0;
  14. }


Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube