Sum of Digits of a Five Digit Number Hackerrank Solution - C
Code :
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int n;
scanf("%d", &n);
//Complete the code to calculate the sum of the five digits on n.
int sum = 0;
while(n!=0){
int r = n%10;
n = n/10;
sum = sum + r;
}
printf("%d",sum);
return 0;
}
Comments
Post a Comment