Solved

# Pascal' Triangle in C, not in C++

Posted on 2003-03-25

I need to write Pascal's Triangle in pure C. I wrote it in C++ and now i have to correct it.

I can't use cout or setw because there are C++ functions. I have a problem "converting" it to C. Can anybody help me?

/* Pascal's Triangle in C++, must be in ANSI C*/

#include <iostream.h>

#include <iomanip.h>

int C(int n, int k)

{

if (k>0 && k<n)

return C(n-1, k-1) + C(n-1, k);

else

return 1;

}

void main()

{

int n, k;

cout << "Pascal's Triangle:\n\n";

for (n=0; n<=12; n++)

{

cout << setw(2) << n << setw(36-3*n) << "";

for (k=0; k<=n; k++)

cout << setw(6) << C(n, k);

cout << endl;

}

}