#include<stdio.h>
int rem,sum;
int calsum(int n)
{if(n!=0){ rem=n%10; sum=sum+rem; calsum(n/10);} return sum;}//------------------------------------------------intmain(){int num,val; clrscr();printf("nEnter a number: ");scanf("%d",&num); val=calsum(num);printf("nSum of the digits of %d is: %d",num,x);return0;}Output :
Enter a number: 123 Sum of the digits of 123 is : 6
No comments:
Post a Comment