Question
Using C programing An integer n is divisible by 9 if the sum of its digits is divisible by 9. Develop a program that uses
Using C programing
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 = 621594
n = 123456
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.
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.
Progranming issignaent 3a finclude hidef h> #include -derivative. h. CONNon defines and nacros /. derivative-specific definitions void ain void) long int nunber 153368 unsigned char digits[6]: DDRB 0xFF; // nake PORTB an output 7vrite a for loop to store the digits in he array 1/ vrite a vhile loop to add up all the digits i su 0 ve could have done this in the first loop, but ve're practicing check if divisible by9 if(sux % 9 .. 0) PORTB -1 PORTB- else vhile(1)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started