C program to find the sum of individual digits of a positive integer.

Written by priya. Posted in Basics

Source Code

/*************************************************************************************/
/* Write a C program to find the sum of individual digits of a positive integer.*/
/*  Download more programs at http://sourcecode4u.com/ */
/*************************************************************************************/



#include<stdio.h>
void main()
{
    int num, k=1, sum=0;
    printf("Enter the number whose digits are to be added:");
    scanf("%d",&num);
    while(num!=0)
    {
        k=num%10;
        sum=sum+k;
        k=num/10;
        num=k;
    }
    printf("Sum of the digits:%d \n",sum);
}

Out Put

output for sum of digits in a given number
BLOG COMMENTS POWERED BY DISQUS