Please help me program the following in C. An integer n is divisible by 9 if the
ID: 673023 • Letter: P
Question
Please help me program the following in C.
An integer n is divisible by 9 if the sum of its digits is divisible by 9.
Develop a program to display each digit, starting with the rightmost digit.
Your program should also determine whether or not the number is divisible by
9. Test it on the following numbers:
n = 154368
n = 621594
n = 123456
Hint: Use the % operator to get each digit; then use / to remove that digit.
So 154368 % 10 gives 8 and 154368 / 10 gives 15436. The next digit extracted
should be 6, then 3 and so on
Explanation / Answer
#include <stdio.h>
int main()
{
int n = 154368;
int sum = 0;
while(n)
{
printf("%d ",n%10);
sum = sum+n%10;
n = n/10;
}
if(sum%9==0)
printf(" True");
else
printf(" False");
return 0;
}