![]() |
Program to print the first 10 lines of pascal's triangle 1 Attachment(s) Program to print the first 10 lines of pascal's triangle #include #include #include long triangle(int x,int y); int main() { clrscr(); const lines=10; for (int i=0;i for (int j=0;j<=i;j++) cout << setw(4) << triangle(i,j); cout << endl; getch(); } long triangle(int x,int y) { if(x<0||y<0||y>x) return 0; long c=1; for (int i=1;i<=y;i++,x--) c=c*x/i; return c; } It just prints out the first ten lines of the pascal's triangle using the 'cout' command. Sample Output 1 10 45 120 210 252 210 120 45 10 1 |
| All times are GMT +5. The time now is 10:08 PM. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.