codescracker


c

C Program to Add Digits of Number



« Previous Program Next Program »


Add Number's Digits in C

To add all the digits of any number in C programming, you have to ask to the user to enter the number to add their digits and display the result

C Programming Code to Add Digits of Number

Following C program ask to the user to enter a number to add the digits of that number:

/* C Program - Add Digits of Number */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int num, rem=0, sum=0;
	printf("Enter a Number :");
	scanf("%d",&num);
	int temp=num;
	while(num>0)
	{
		rem=num%10;
		sum=sum+rem;
		num=num/10;
	}
	printf("Sum of the digits of %d is %d",temp,sum);
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program add number digits

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test