Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Answer:
- Algorithm:
- Step 1: Start
- Step 2: Input a 'whole number' and assign it to N
- Step 3: Set counter=0
- Step 4: Extract unit digit from the number, X=N%10 (Remainder calculation)
- Step 5: Compare the extracted digit with 7, Is X=7 ?
- Step 5.1: If 'yes' increase the counter by 1, counter=counter + 1
- Step 6: Drop the unit digit and consider the remaining part as new input, N=N/10 (integer division)
- Step 7: If N is not equal to zero (is N!=0 ?) goto step 4
- Step 8: Output counter
- Step 9: Stop
- ----------------------------------------------------
- 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