Program to calculate the sum of the digits of the number in c-programming.
In this program we will now takes input form the user and calculate the sum of the digits of the number in c-programming languages.
#include<Stdio.h>
int sum(int n);
main()
{
int x,s;
printf("enter the number");
scanf("%d",&x);
s=sum(x);
printf("the sum of the number is %d",s);
getch();
}
int sum(int n)
{
int result;
if(n==0)
return(0);
result=n%10+sum(n/10);
return(result);
getch();
}
int sum(int n);
main()
{
int x,s;
printf("enter the number");
scanf("%d",&x);
s=sum(x);
printf("the sum of the number is %d",s);
getch();
}
int sum(int n)
{
int result;
if(n==0)
return(0);
result=n%10+sum(n/10);
return(result);
getch();
}
output:-
For more c-programming:-

spperbbbbbbbbbbbbbbbbb
ReplyDelete