Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 3a-50 points An integer n is divisible by 9 if the sum of its digits is

ID: 2267775 • Letter: P

Question

Problem 3a-50 points An integer n is divisible by 9 if the sum of its digits is divisible by 9 Develop a program that uses this method to determine whether or not a number is divisible by 9. Test it on the following numbers: n = 154368 n = 621 594 n = 123456 Use the % operator to get each digit, then use / to remove that digits 154368 % 10 gives 8 and 154368 / 10 gives 15436, The next digit extracted should be 6, then 3 and so on. s On the next page is a screen shot of a working solution with the loops missing. After you write your loops and get the program running, you can test it by hitting run, then hitting the halt button. Examine memory at PORT B to see if it worked. PORT B is at address 01 in the memory window

Explanation / Answer

The while loop logic used to find if a number is divisible by 9 or not is given below.

void main()

{ int n,b,s;

s=0;

printf("Enter any number ");

scanf("%d" , &n);

while( n!=0)

{ b=n%10;

s=s+b;

a= n/10;

}

if(s%9==0)

{ printf(" The number %d is divisible by 9", n);

}

else

{ printf(" The number %d is not divisible by 9", n);

}

} // end of program

put n= 154368 and check correct result

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote