Pascal triangle using recursion.

Hi! I have written this program for Pascal's Triangle using recursion but I m not sure whether it can be termed as 'Recursion' coz it still uses loops , I have basically used the runtime stack but just a bit confused whether the program can be termed as a recusive program or not? Thanks in advance!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<iostream.h>
Using namespace std;

PrintPascal(int a)
{
if (a==1)
cout<<a<<endl;

else
{
PrintPascal(a-1);

for(int i=1; i<=a; i++)
cout<<i<<" ";

for(int z=(a-1); z>0; z--)
cout<<z<<" ";

cout<<endl;
}
}
int main()
{
int n;
cout<<"Enter Number of Rows : ";
cin>>n;

PrintPascal(n);
return 0;
}
Last edited on
The function calls itself and there is an end condition that will stop the recursion, so it is recursive. However, does it produce the correct output?

It does differ from algorithms that a websearch for "Pascal's triangle recursion" does return.
Yes it gives the right output. Thanks!
Topic archived. No new replies allowed.