I have a project about making pascal triangle using recursive function.
This is the example output:

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

Hint:(x+y) n=>exponent.
*Give me an idea about this project. Thanks!

Do you know how to create a pascal triangle without recursive?

If so then doing it recursive won't be that far off. Give it a go and see
what happens.

/* Program to print the Pascal's triangle recursively */

#include<stdio.h>

int pascal(int,int);
void space(int,int);

main()
{
	int num,i,j;
	printf("\nEnter the no. of rows required: ");
	scanf("%d",&num);
	for(i=1;i<=num;i++)
	{
		space(num-i,3);
		for(j=1;j<=i;j++)
		{
			printf("%3d",pascal(i,j));
			space(1,3);
		}
		printf("\n");
	}
}

int pascal(int row,int column)
{
	if(column==0)
		return 0;
	else if(row==1&&column==1)
		return 1;
	else if(column>row)
		return 0;
	else
		return (pascal(row-1,column-1)+pascal(row-1,column));
}

void space(int num,int mul)
{
	int i;
	num*=mul;
	for(i=0;i<num;i++)
		printf(" ");
}

Edited 6 Years Ago by Nick Evan: Added code-tags

Comments
He only wants the idea.Dont give code directly!

This code will do the job

#include <iostream>

long calc(int n, int r) {
     if ((n == 0) || (r == 0) || (n == r)) return 1;
     else return (calc(n-1,r-1) + calc(n-1,r));
} // This is the recursive function

int main() {
    printf("Enter a number = ");
    int num;
    scanf("%i", &num);
    for (int i = 0; i<=num; i++) {
        for (int j = num; j > i; j--) printf("   ");
        for (int k = 0; k <= i; k++) printf("%6d", calc(i,k));
        printf("\n");
    } // End of for loop
    return 0;
}

Edited 5 Years Ago by shellexecutor: n/a

Comments
bump
Give a chance to him to try something.

@shellexecutor: Don't bump 2 year old threads (the OP probably doesn't care anymore), and don't provide fully working code, especially for such a classic homework problem (pascal triangle) and when the OP didn't show much effort of his own.

This article has been dead for over six months. Start a new discussion instead.