using recursion find the sum of the digit

 // add digits of the number using recurssion

#include<stdio.h>

int add_digits(int);

int main()

{

    int n,result;

    printf("enter the number whose sum of digit you wnat:");

    scanf("%d",&n);

    result= add_digits(n);

    printf("%d",result);

    return 0;

}

int add_digits(int n)

{

    static int sum=0;

    if(n==0){

        return 0;

    }

    sum=n%10+add_digits(n/10);

    return(sum);

    

    

    

}

Comments

Popular posts from this blog

Use of function in mathematics

My resume using HTML and CSS