UncleCoder.com

UncleCoder.com

Free programming examples and instructions

C program to find the sum of each digits

C program to find the sum of each digits

by Krishna viswambharan


Posted on 25 Sep 2017 Category: C Views: 75

Edited on 27 Sep 2017



This article explains the source code of the C program to find the sum of digits of a given integer.  The program runs successfully and the output is also given below.

#include <stdio.h>
#include <conio.h>
void main()
{
	int num,digit,sum=0;
	printf(“enter the number :”);
	scanf(“%d”,&num);
	while(num>0)
	{
		digit=num%10;
        sum=sum+digit;
        num=num/10;
    }
    printf(“sum of the digits =%d”,sum);
    getch();
}

 

output



Leave a Comment:


Advertisement