C Programming
Computer Programming

C Program to Calculate the Sum of Natural Numbers using recursion



Write a Program in C using function to Find the sum of natural numbers using recursion

\* C Program to Calculate the Sum of Natural Numbers using recursion *\

# include < stdio.h >
# include < conio.h >
int   addNumbers(int n) ;

int   main( )
{

int num ;
printf("\n Enter the last positive integer : ") ;
scanf("%d", &num) ;
printf(" Sum of All Natural Number = %d",addNumbers(num)) ;
return 0 ;

}

int   addNumbers(int n)
{

if( n != 0 ) ;
      return n + addNumbers( n - 1 ) ;
else
      return n ;

}

Output of Program :

Output of C Program to Calculate the Sum of Natural Numbers using recursion