You are on page 1of 1

#include<stdio.h> #include<conio.

h> int sumofdigits(int); int count, a, n, i, c, sum; int main() { printf("enter the number\n"); scanf("%d", &n); sum=sumofdigits(n); printf("sum of the digits until the sum is reduced to one digit is : %d", su m); getch(); } int sumofdigits(int n) { a=n; count=0; do { n=n/10; count+=1; }while(n!=0); i=0; sum=0; n=a; while(i<count) { c=n%10; sum=sum+c; n=n/10; i++; } if(sum/10!=0) sum=sumofdigits(sum); return (sum); }

You might also like