954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

pascal triangle

here's anader program..
the output should be like this..
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
........

and here's d c0de..dunn0 if this is right..

#include
const int leftcorner=1;
const int rightcorner-=1;
const int topelement=1;
int *pascal trianglr=0;
int buildtriangle(int tmpPascalrow;
{
int prev,curr,next;
int tmpRow, elementIndex=0;
int buffer=0;

if(tmpPascalRow==1)
{pascalTriangle[0]=topElement;
return 1;
}
pascalTriangle[0]=leftcorner;
pascalTriangle[1]=rightCorner;

for(tmpRow=3;tmpRow<=tmpPascalRow;tmpRow++)
{
pascalTriangle[0]=leftCorner;
pascalTriangle[tmpRow-1]=rightCorner;
buffer=leftCorner;

for(elementIndex=1;elementIndex

darkeinjel04
Newbie Poster
13 posts since Sep 2006
Reputation Points: 18
Solved Threads: 0
 

link . EDIT: Your code can not be compiled, remove the errors.

andor
Posting Whiz in Training
276 posts since Jun 2005
Reputation Points: 251
Solved Threads: 29
 

I have Made a new program..but still there is a error declaration...
i realy nid this program tomorrow so pls help me....re check

#include<stdio.h>
void main()
{
int line,c,n,x;
void pasc(int);
printf("\n\nEnter the no. of rows: ");
scanf("%d",&line);
printf("\n\n\n");
printf("\nPascal's triangle :\n");
for(x=line-1;x>=0;x--)
  printf("   ");
printf("  1\n\n");
for(n=2;n<=line;n++)
{
 for(c=line-n;c>=1;c--)
  printf("   ");
 pasc(n);
 printf("\n");
}
}
void pasc(int n)
{
 int r;
 long fact(int);
  for(r=0;r<=n;r++)
   printf("%3ld   ",fact(n)/(fact(n-r)*fact(r)));
}
  long fact(int v)
{
  if(v==1||v==0)
   return(1);
  else
   return(v*fact(v-1));
}
darkeinjel04
Newbie Poster
13 posts since Sep 2006
Reputation Points: 18
Solved Threads: 0
 

in pasc(int):

long fact(int);



That declaration of a function should me in main() where you declare pasc(int)

Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 
in pasc(int): That declaration of a function should me in main() where you declare pasc(int)



what should i put then??

darkeinjel04
Newbie Poster
13 posts since Sep 2006
Reputation Points: 18
Solved Threads: 0
 

the problem here is

}
  long fact(int v)
{


what should i replace?? The expression is Syntax in Function Main..
pls help

darkeinjel04
Newbie Poster
13 posts since Sep 2006
Reputation Points: 18
Solved Threads: 0
 

As I said:

You are trying to declare the function fact(int v) inside the function pasc(int). That's not possible...

your program should start like this:

int main()
{
 
void pasc(int);
long fact(int);
int line,c,n,x;
 
//blabla
}


and then delete the line

long fact(int);


from void pasc(int)

Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 

A well detailed Pascal Triangle code snippet here:

http://www.daniweb.com/techtalkforums/post233793-11.html

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 
I have Made a new program..but still there is a error declaration... i realy nid this program tomorrow so pls help me....re check


Why should we have to check your code? You should be able to tell if it works or not. And then if you have a problem, you can create a thread for that problem. If you want someone to do your testing for you, you better start making offers for payment.

That said, the code seems to work fine. At least, it compiles and runs correctly (though I only did 1 trial) on VS2005, though I was surprised by that. Few notes:

void main() // should be int main(), as per any standard of C or C++
{
    int line,c,n,x;
    void pasc(int); // don't declare a function within a function. 
                      // Declare it before main() instead.
    // ...rest of the code
Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You