Find the sum of digits of a number using c programming?
Answers
Answered by
0
1. Take the integer as input.
2. Divide the input integer by 10, obtain its remainder and quotient.
3. Increment the new variable with the remainder got at step 2.
4. Repeat the step 2 & 3 with the quotient obtained until the qoutient becomes zero.
5. Print the output and exit.
Hope this will help you!!!
2. Divide the input integer by 10, obtain its remainder and quotient.
3. Increment the new variable with the remainder got at step 2.
4. Repeat the step 2 & 3 with the quotient obtained until the qoutient becomes zero.
5. Print the output and exit.
Hope this will help you!!!
Answered by
4
#include<stdio.h>
int main() {
int n;
int s = 0;
while (n > 0) {
int r = n % 10;
s = s + r * 10;
n = n / 10;
}
printf("sum of digits in number is%d",s);
return 0;
}
int main() {
int n;
int s = 0;
while (n > 0) {
int r = n % 10;
s = s + r * 10;
n = n / 10;
}
printf("sum of digits in number is%d",s);
return 0;
}
Similar questions