Computer Science, asked by facebook12367, 3 months ago

write an algorithm and draw a flow chart to find sum of digits of a number​

Answers

Answered by fazeenkhan236
2

Answer:

Step 1: Get number by user

Step 2: Get the modulus/remainder of the number

Step 3: sum the remainder of the number

Step 4: Divide the number by 10

Step 5: Repeat the step 2 while number is greater than 0.

Let's see the sum of digits program in C.

Answered by aburaihana123
2

Answer:

Algorithm and flow chart for the sum of digits of a number has been given below.

Explanation:

Algorithm  for sum of digits in a given number

Step 1 : Get the number

Step 2 :Construct a variable to hold the total and initialize it to 0.

Step 3: Repeat steps 2 and 3 until the result is not 0.

Step 4: Divide the number by 10 to obtain the rightmost digit using the remaining "percent" operator, then add it to the total.

Step 5: Use the '/' operator to divide the integer by 10 to eliminate the last digit on the right.

Step 6: Print or submit the total.

Program for sum of digits of a number:

#include<stdio.h>  

int main()    

{    

int n,sum=0,m;    

printf("Enter a number:");    

scanf("%d",&n);    

while(n>0)    

{    

m=n%10;    

sum=sum+m;    

n=n/10;    

}    

printf("Sum is=%d",sum);    

return 0;  

}  

Flow chart of sum of digits of the given number has been given below

#SPJ2

Attachments:
Similar questions