# Find sum of individual digits of number using function

This article illustrates the concept how to find sum of individual digits of number using function in c/c++. Here is the source code and output of both the programs.

## C Programming language

#### Program

``````
#include<stdio.h>
#include<conio.h>
void main()
{
int num,res;
clrscr();
printf("Enter Number:- ");
scanf("%d",&num);
res=sum(num);
printf("Sum of individual digit of number is:- %d",res);
getch();
}
int sum(int num)
{
int rem,sum=0;
while(num>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
return sum;
}

``````

#### After successfully compiling and executing the above C program,output is:- ## C++ Programming language

#### Program

``````
#include<iostream.h>
#include<conio.h>
int sum(int);
void main()
{
clrscr();
int num,res;
cout<<"Enter Number:- ";
cin>>num;
res=sum(num);
cout<<"Sum of individual digit of number is:- "<<res;
getch();
}
int sum(int num)
{
int rem,sum=0;
while(num>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
return sum;
}

``````

#### After successfully compiling and executing the above C++ program,output is:- #### About article

Written By:- Admin

Published on:- 09/08/2018

Published By:- Snapcout

Don't forget to share the article if you like it:-