Generating triangular number up to n terms using recursive function

Program


#include<stdio.h>
#include<conio.h>

/* Function prototype */
int triangular(int n);

/* Main Function */
int main()
{
 int term, i;
 clrscr();
 printf("How many terms?\n");
 scanf("%d", &term);
 printf("First %d triangular numbers are:\n", term);
 for(i=1; i<=term; i++)
 {
  printf("%d\t", triangular(i));
 }
 getch();
 return 0;
}
/* Function definition */
int triangular(int n)
{
 if(n<=1)
 {
  return 1;
 }
 else
 {
  return n+triangular(n-1); /* Recursive Function */
 }
}