Saturday 29 July 2017

INLAB 1


Given a four digit number 'x', write an algorithm to check whether ‘x’ is divisible by the sum of the digits of ‘x’. A number ‘a’ is said to be divisible by ‘b’, if the remainder is zero when ‘a’ divides ‘b’.
For example, the number ‘x’ is 1234 is not divisible by 10, because if we divide ‘1234’ with the sum of its individual digits (1+2+3+4 = 10), the remainder is not zero.  
Code:
n=int(input())
m=n
s=0
while(n):
last=n%10
s=s+last
n=n//10
if(m%s==0):
print('Divisible')
else:
print('Not divisibe')

Input:
The number 'n'

Processing:
while(n):
last=n%10
s=s+last
n=n//10

Output:
Print either 'Divisible' or 'Not divisible'

Pseudo Code:
1) Read the number 'n' to be checked
2) Find the sum of the digits of 'n' and let it be 's'
3) If 'n' is divisible by the sum => n%s==0
4) If 'n' is divisible by 's' then print 'Divisible' else print 'Not divisible'

Flow Chart:




******************************************************************************************

7 comments:

  1. Abe chutiye don't write python code in flowchart only geniuses will understand your flowchart.

    ReplyDelete
    Replies
    1. Flowchart is not made by seeing who is going to read it. It is drawn the way it should be. If you don't like the way it is drawn, you can draw it by yourself. If you can't be thankful to the person providing you the solutions, at least don't use slang words please.

      Delete
    2. Thank you. You people's support is only what is gonna inspire me to continue..
      By the way those comments don't affect it.

      Delete
  2. Pankaj Sir can u confirm with the faculty that u can use python specific symbols in the flowchart

    ReplyDelete
  3. I was more than happy to uncover this great site. I need to to thank you for your time!! I definitely enjoyed every bit of it and I have you bookmarked to see new information on your blog.

    ReplyDelete
    Replies
    1. Welcome Mounish. Your support is what inspires me.

      Delete