Q.Given a four digit number x devise an algorithm to check whether x is divisible by the sum of the digits of x.
I am providing you guys with algorithm and flowchart of the question
Algorithm
Step1. Get the number x
Step2. intialize total as 0 and copy as x.
Step3. Repeat until copy is 0(while copy!= 0)
Step3.1. change total as sum of total and copy%10(total = total + (copy%10))
Step3.2. change copy as copy/10 and remove the decimal part from copy/10.
Step4. when x is divided by total and if the remainder obtained from that division is zero then x is divisible by its sum else its not divisible by its sum.
Step5. End
Guys if u find an error please post the error in the comments and i'll update the error as soon as i can. I am a human and humans have a tendency to make mistakes!!!
I am providing you guys with algorithm and flowchart of the question
Algorithm
Step1. Get the number x
Step2. intialize total as 0 and copy as x.
Step3. Repeat until copy is 0(while copy!= 0)
Step3.1. change total as sum of total and copy%10(total = total + (copy%10))
Step3.2. change copy as copy/10 and remove the decimal part from copy/10.
Step4. when x is divided by total and if the remainder obtained from that division is zero then x is divisible by its sum else its not divisible by its sum.
Step5. End
Guys if u find an error please post the error in the comments and i'll update the error as soon as i can. I am a human and humans have a tendency to make mistakes!!!
No comments:
Post a Comment