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

  1. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!