| | |
pascals triangle
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2004
Posts: 2
Reputation:
Solved Threads: 0
Hi there are many logics behind this problem. This is the simple logic. Though it is inefficient, this will give you a better approach to this program
a[0] = 1
for(i=0;i<n;i++){
for(j=0;j<=i;j++){
Value_to_print = a[j-1]+a[j];
/* Print the values in the order you want */
}
a[j] = 0
a[j-1] = Value_to_print
}
a[0] = 1
for(i=0;i<n;i++){
for(j=0;j<=i;j++){
Value_to_print = a[j-1]+a[j];
/* Print the values in the order you want */
}
a[j] = 0
a[j-1] = Value_to_print
}
Well, you can try this code, but I don't know if it will work beyond n=9.
btw, I didn't know it was called a pascal's triangle. I used to refer to it just as a no. pyramid or whatever.
C++ Syntax (Toggle Plain Text)
#include <iostream.h> #include <conio.h> /* This program creates a half pyramid of nos. Created on 12.6.2k3. */ void main() { int n, i, r; cout<<"Enter the number of numbers: "; cin>>n; if (n>9) cout<<"\n This won't work out. "; else { for (i=1; i<=n; i++) { for (r=1; r<=i; r++) { cout<<r; } cout<<endl; } } getch(); } /* Output: Enter the number of numbers: 7 1 12 123 1234 12345 123456 1234567 */
![]() |
Similar Threads
- Custom pascal triangle ? (C)
- Pascal Triangle program that needs to convert from C to C# (C)
- HELP!!! - Wanted : Pascal's Triangle with loops ? (C#)
- pascals triangle (C++)
- Pascals triangle (Functions) (C++)
Other Threads in the C++ Forum
- Previous Thread: sum of series
- Next Thread: Single brace use?
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return string strings struct studio system template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





