473,473 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Pascal_Triangle

AmLegacy
6 New Member
Hi,

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
  1. int factorial (int n)
  2.  
  3. {
  4.     if (n==0) return 1;
  5.     else return (n*factorial(n-1));
  6.  
  7.  
  8. }
  9.  
  10. int combo (int n, int r)
  11.  
  12. {
  13.     return (factorial (n))/(factorial (r) * (factorial (n-r)));
  14.  
  15. }
  16.  
  17.  
  18. //For every iteration of the nested loop, I want to call combo once, and print the returned value.
  19. int c (int n, int r)
  20.  
  21. {    
  22.  
  23.   int i, j;
  24.  
  25.  
  26.    for (i = 0; i<=5; ++i) //n will be the test value to stop loop
  27.  
  28.     {
  29.  
  30.          for (j = 0; j<=i; ++j)
  31.  
  32.      {
  33.  
  34.          printf ("%5d", combo (i, j));
  35.          if (i==j)
  36.          {
  37.  
  38.              printf("\n");
  39.          }
  40.      }
  41.  
  42.  
  43.     }
  44. }        
  45.  
  46. int main ()
  47. {
  48.     int a , b, n;
  49.  
  50.  
  51.     printf ("Please enter a value> \n");
  52.     scanf ("%d", &n);
  53.  
  54.     int triangle = c (a, b); //call my c function (the loop)
  55.  
  56.     printf("%d", triangle);
  57.  
  58.  
  59.  
  60.     }
Feb 25 '08 #1
1 1348
weaknessforcats
9,208 Recognized Expert Moderator Expert
Your code won't compile. Function c() does not return a value.

The variables a and b are not initialized.

etc...
Feb 25 '08 #2

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.