/* A program to find the sum of given non-negative integer numbers using a recursive function */
#include<stdio.h>
int sum(int a)
{
scanf("%d",&a);
if(a<=0)
return a; /*can return zero value as well*/
else
return(a+sum(a));
}
int main()
{
int a;
printf("enter numbers\n");
printf("sum= %d",sum(a));
return 0;
}
No comments:
Post a Comment