Find sum of digits of a given number.

This post content:-
Algorithm
Flowchart
C code
Output
Pdf notes

Algorithm:-
Step 1:- start.
Step 2:- declare variable num.
Step 3:- make a function to get a sum.
As follow:-
int getSum(int n)
{
    int sum = 0;
    while (n != 0) {
        sum = sum + n % 10;
        n = n / 10;
    }
    return sum;
}
Step 4:- end.

Flowchart:-

C code:-
Output:-
 Try it yourself:-

Comments

Popular posts from this blog

Develop and execute C Program to Add Two Distances given in kilometer-meter Using Structures.

Find the greatest of the three numbers using conditional operators.