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!

beau_nerdathen
0
Newbie Poster

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!

Jump to PostYou need to show us some efford before we can help you xD

Jump to PostDo 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.

poncho4all
0
Light Poster

You need to show us some efford before we can help you xD

mrnutty
761
Senior Poster

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.

chikkupa
0
Newbie Poster

/* 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
by Nick Evan because:
*
Added code-tags *

Onlineshade
commented:
He only wants the idea.Dont give code directly!
+0

shellexecutor
-3
Newbie Poster

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
by shellexecutor because:
*
n/a *

Onlineshade
commented:
Give a chance to him to try something.
+0

mike_2000_17
commented:
bump
-3

mike_2000_17
2,669
21st Century Viking
Team Colleague
Featured Poster

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.

Broken Link

**You're trying to visit a URL that doesn't currently exist on the web.**
Most likely, a member posted a link a long time ago to a web page that has since been removed.
It's also possible that there was a typo when posting the URL.
We redirect you to this notice instead of stripping out the link to preserve the integrity of the post.