Sum of Digits of a Five Digit Number | HackerRank - Samsus Salehin Sabbir

Header Ads

Sum of Digits of a Five Digit Number | HackerRank


Problem Link : Sum of Digits of a Five Digit Number

Solution :
      Develop by
 Samsus Salehin Sabbir 

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>

  5. int main() {
  6.     int n,i,sum=0,rem;
  7.     scanf("%d", &n);
  8.     //Complete the code to calculate the sum of the five digits on n.
  9.     while(n!=0)
  10.     {
  11.         rem =n%10;
  12.         sum=sum +rem;
  13.         n=n/10;
  14.     }
  15.     printf("%d\n",sum);
  16.     return 0;
  17. }

No comments

Powered by Blogger.