jaredec18

Untitled

Sep 20th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. Answer:
  2.  
  3. Algorithm:
  4.  
  5. Step 1: Start
  6.  
  7. Step 2: Input a 'whole number' and assign it to N
  8.  
  9. Step 3: Set counter=0
  10.  
  11. Step 4: Extract unit digit from the number, X=N%10 (Remainder calculation)
  12.  
  13. Step 5: Compare the extracted digit with 7, Is X=7 ?
  14.  
  15. Step 5.1: If 'yes' increase the counter by 1, counter=counter + 1
  16.  
  17. Step 6: Drop the unit digit and consider the remaining part as new input, N=N/10 (integer division)
  18.  
  19. Step 7: If N is not equal to zero (is N!=0 ?) goto step 4
  20.  
  21. Step 8: Output counter
  22.  
  23. Step 9: Stop
  24.  
  25. ----------------------------------------------------
  26.  
  27. If we consider only repeating tasks as judging factor and steps 4 to 6 as one operation, then the number of operations will be 1 if the givin number is single-digit number or n if the given number is an n-digit number. So, minimum number of operations=1 and maximum number of operations is n, where n is the number of digits in the given whole number.
Advertisement
Add Comment
Please, Sign In to add comment