i need help in making pascal triangle in turbo c
i need help in making pascal triangle in turbo c
can someone help me?? i need the program in making a pascal triangle using for loop.. thanks in advance...
4 Dec 07, 2:20PM
Try:
std::vector<int> row(n + 1); row[0] = 1; for (int j = 1; j <= n; j++) for (int i = j; i; row[i] += row[i - 1], i--); return row;Though depending on what you're doing with the data, you may want to just write the results to screen.
We can't see the output?
Is CodeCogs working for you?
can i send it at your email.. i cant upload the file...
Hi.. We've noticed the error also.. We're sorting it out.. Thx..
4 Dec 07, 3:41PM
Fixed. You'll find the file has been uploaded, its just that it wasn't appending your user id to the path.
i.e. If you have
\download output.txt
It should have been
\download 14134/output.txtWhere 14134 is your unique ID. The upload system now does this correctly. Thanks for finding the bug.
4 Dec 07, 3:46PM
4 Dec 07, 3:54PM
4 Dec 07, 4:47PM
Hey,
I see your problem. Have you considered first writing each line of your triangle to a std::list of string. As you do you can note the lenght of the longest line, and then go back to the top of the list and output appropriate spaces to center everything.
Can't see how you can predict the necessary spacing to insert on the left side, until you've calculated each row of the triangle. Obviously the number of row and the size of the numbers within each row will impact the spacing need on the rows above.
4 Dec 07, 4:57PM
can you help me fix it??
5 Dec 07, 4:40PM
#include<stdio.h> #include<conio.h> void main() { int a[10][10]; int i,j,c,n; clrscr(); printf("enter how many line do you want: "); scanf("%d",&n); a[1] [1]=1; printf("%39d ",a[1][1]); a[2][1]=1;a[2][2]=2;a[2][3]=1; printf("\n%37d %d %d ",a[2][1],a[2][2],a[2][3]); for(i=3;i<=n;i++) { a[i][1]=1; printf("\n%36d ",a[i][1]); j=2;c=3; while(j<=i) { a[i][j]=a[i-1][c-1]+a[i-1][c-2]; printf("%d ",a[i][j]); c=c+1; j=j+1; } a[i][j]=1; printf("%d",a[i][j]); } getch(); } *******************output********************* enter how many lines you want: 7 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 i have problems in making the shape a triangle..
5 Dec 07, 4:57PM
Are you still stuck?
try doing something like this. First you'll need these libraries:
#include<sstream> #include<string>You now need a new NumToString function, which I also just posted on the forum
std::string NumToString(double num) { std::stringstream s; s << num; return s.str(); }Then you want to create a nice list of your data, but remember the largest array you find, so create:
std::list<std::string> rows; std::string tmp; int maxlen=0;Now everywhere you're using printf, replace this with the construction of the string, then when you're finished with that line, push it into the list container and not the max length of the line. Heres the first second line for ya:
tmp=NumToString(1)<<" "<<NumToString(2)<<" "<<NumToString(1); maxlen=max(maxlen,tmp.length()); rows.push_back(tmp);Then when you're done creating as many lines as you want, you need to cycle through the list and output with your printf, only you'll be wanting to push in some blanks to ensure everything is central. --- On a side note, this looks very much like homework. I don't do other peoples homework, so this is all the help you'll get from me :)
5 Dec 07, 5:13PM
thnx.. i'll try to do it.. ^^
Login