Right now my program runs a beautiful pascal triangle up to 5. The only problem is that I want the user's input n to be the last row the triangle prints. When I replace n for in 5 in the first for loop it doesn't print the triangle. I know it's something simple. I've been focused so many hours trying to get this to work I've forgotten the basics..maybe.
Expand|Select|Wrap|Line Numbers
- int factorial (int n)
- {
- if (n==0) return 1;
- else return (n*factorial(n-1));
- }
- int combo (int n, int r)
- {
- return (factorial (n))/(factorial (r) * (factorial (n-r)));
- }
- //For every iteration of the nested loop, I want to call combo once, and print the returned value.
- int c (int n, int r)
- {
- int i, j;
- for (i = 0; i<=5; ++i) //n will be the test value to stop loop
- {
- for (j = 0; j<=i; ++j)
- {
- printf ("%5d", combo (i, j));
- if (i==j)
- {
- printf("\n");
- }
- }
- }
- }
- int main ()
- {
- int a , b, n;
- printf ("Please enter a value> \n");
- scanf ("%d", &n);
- int triangle = c (a, b); //call my c function (the loop)
- printf("%d", triangle);
- }