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

Programming Assignments are due the Wednesday after they are assigned, at midnig

ID: 2268093 • Letter: P

Question

Programming Assignments are due the Wednesday after they are assigned, at midnight. For each problem, paste your code and a screen shot that verifies the program worked into a Word document. Use CodeWarrior, PORTB for output, taking screen shots of memory to verify that the program worked. Problem 3a-50 points C Enbb e deed An integer n is divisible by 9 if the sum of its digits is divisible by 9Develop a program that uses this method to determine whether or not a number is divisible by 9. Test it on the following numbers: n = 1 54368 n = 621 594 n 123456 Use the % operator to get each digit; then use / to remove that digitise so 154368 00 10 gives 8 and 154368 / 10 gives 15436, The next digit extracted should be 6, then 3 and so on. seEP 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. Problem 3b -50 points

Explanation / Answer

Hello,
       Please find the answer attached below. If the answer has helped you please give a thumbs up rating. Thank you and have a nice day!

int n = 154368;           // main input number
int sum_of_digits = 0;       // variable to store sum of digits
int a=n;           // temporary variable for n
int divide_by_nine=0;       // status of number divisible by 9 (1 = divisible, 0 = not divisible)

while(a>10)           // carry out loop till 'a' reduces to single digit
{
   sum_of_digits = sum_of_digits + (a%10);
   a = a/10;
}

sum_of_digits = sum_of_digits + a;   // carry out the summation till last digit

if(sum_of_digits%9==0)           // if divisible by 9, change status of variable
divide_by_nine = 1;

Note that you have to include all the necesary header files before running the program. Since the header files depends on the board where you are running the program, I did not mention it in the code. Also, for the other numbers, check out the results by replacing the value of 'n' with those numbers