### Write a C Program to Find the Sum of Individual Digits of Positive Integer

In this article, we will discuss how to write a C program to find the sum of individual digits of a positive integer.

# ALGORITHM:

Step 1: Start

Step 3: Initialize sum ← 0

Step 4: while(n!=0) Begin

Step 5: r←n%10

Step 6: sum←sum+r

Step 7: n←n/10 End

Step 8: Print “sum”

Step 9: Stop

# Program: Write a C Program to Find the Sum of Individual Digits of Positive  Integer

``````#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,sum=0;
clrscr();
printf("ENTER A POSITIVE INTEGER \n");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
printf("THE SUMOF INDIVIDUAL DIGITS OF A POSITIVE INTEGER IS -> %d",sum);
getch();
}
``````

SAMPLE INPUT:

``````ENTER A POSITIVE INTEGER
5 3 2 1
``````

EXPECTED OUTPUT:

``THE SUM OF INDIVIDUAL DIGITS OF A POSITIVE INTEGER IS -> 11 ``

# Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course