ProAnswers.org

Write a C program to calculate triangular number of an entered number with recursion function method?

r

 #include<stdio.h>

#include<conio.h>

void main()

{

int n,t,tri_num(int);

clrscr();

printf(“Enter a number:”);

scanf(“%d”, &n);

t-tri_num(n);

printf(“\n Triangular number of %d is %d ”, n,t);

}

tri_num(m)

{

int f=0;

if(m= =0)

return(f);

else

f=f+m+tri_num(m-1);

return(f);

getch();

}

Output:

Enter a number: 5

Triangular number 5 is 15