Question
Problem #1: Flowchart (40 marks) Draw the flowchart and write the pseudocode for an algorithm that: Reads an integer and then prints N the number
- Problem #1: Flowchart (40 marks)
Draw the flowchart and write the pseudocode for an algorithm that:
- Reads an integer
- and then prints N the number of digits in the integer
- and the S sum of the digits.
For example, given the number 12345, it would print:
- that there are N= 5 digits
- with a sum S = 15
Hint:
Given the number 6761
How many digits it has?
Initially
S=0; N =0
6761 divided by ten : quotient is 676 remainder is = 1, so I have
number of digits =number of digits +1=1 , sum = sum+ 1 =1
676 divided by ten : quotient is 67 and remainder is =6, so
number of digits = number of digits+1 =2, current sum = sum + 6= 7
67 divided by ten : quotient is 6, remainder is 7,
so number of digits = number of digits +1 = 3, current sum is sum+7 =14
6 divided by 10 : quotient is 0, remainder is 6,
so number of digits = number of digits+1, sum= sum +6=20
quotient is 0 so we stop
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