Header Ads

Header ADS

Write a program to find the sum of the divisors of a number given by the keyboard using recursive function:

 Write a program to find the sum of the divisors of a number given by the

keyboard using recursive function:


#include<stdio.h>

int factor(int n, int i,int sum){

    if(i<=n){

        if(n%i==0){

         sum=sum+i;

        }

        factor(n,i+1,sum);

    }

    else{

    printf("%d ",sum);

    }

}

int main(){

    int num,sum=0;

    scanf("%d",&num);

    factor(num,1,sum);

}


No comments

Powered by Blogger.