It can be done in this way:
The main source code is given below:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<conio.h> | |
int sum (int); | |
int main() | |
{ | |
int num,x; | |
printf("enter the number whose sum is to be find"); | |
scanf("%d",&num); | |
x=sum(num); | |
printf("the sum of the entered number is %d",x); | |
getch(); | |
} | |
int sum(int n ) | |
{ | |
int r,s=0; | |
while (n!=0) | |
{ | |
r=n%10; | |
s=s+r; | |
n=n/10; | |
} | |
return s; | |
} | |

0 comments :
Post a Comment