Write a program to calculate the sum of a five digit number.
In this program we will take an input of a number. And calculate the sum of the digits of the entered number.
This post content:-
- Algorithm
- Flowchart
- C code
- Output
- Pdf notes
Algorithm
Step 1:- start.
Step 2:- declare variables named "number, last_digit, next_digit, total "
Step 3:- take the input of the variable number whose sum of digits is to be calculated.
Step 4:- calculate the sum of the digits of the entered number.
by using:-
last_digit = number%10;
total = last_digit;
next_digit = (number/10) % 10;
total = total + next_digit;
next_digit = (number/100) % 10;
total = total + next_digit;
next_digit = (number/1000) %10;
total = total + next_digit;
next_digit = (number/10000) %10;
total = total + next_digit;
Step 5:- print the total.
Step 6:- end.
Flowchart:-
C code:-
Output:-
Comments
Post a Comment