15.The sum of first Nth natural number using recursion

 #include<stdio.h>

int natural(int x);

int main(){
    int num;
    printf("Enter the Nth number :");
    scanf("%d",&num);
    printf("\nThe sum of first natural number till %d is :%d",num,natural(num));
    return 0;
}
    int natural(int x)
    {  
        if(x==1)
        return x;
        else
        return x+natural(x-1);
    }

Comments