0% found this document useful (0 votes)
2 views1 page

Recursion

This C program calculates the sum of the first n natural numbers using a recursive function. The user is prompted to enter a value for n, and the program outputs the calculated sum. The recursion continues until it reaches the base case of n equal to 1.

Uploaded by

ranadhruv487
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Recursion

This C program calculates the sum of the first n natural numbers using a recursive function. The user is prompted to enter a value for n, and the program outputs the calculated sum. The recursion continues until it reaches the base case of n equal to 1.

Uploaded by

ranadhruv487
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

// Online C compiler to run C program online

#include <stdio.h>

int natural(int n){

if(n==1){

return 1;

else{

return n+natural(n-1);

int main() {

int n;

printf("Enter n");

scanf("%d",&n);

printf("sum of first %d natural numbers is %d",n,natural(n));

return 0;

You might also like