BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan

BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan (http://bzupages.com/)
-   Object Oriented Programming (http://bzupages.com/322-object-oriented-programming/)
-   -   Program to print the first 10 lines of pascal's triangle (http://bzupages.com/f322/program-print-first-10-lines-pascals-triangle-14666/)

bonfire 09-03-2011 12:15 AM

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=1;j cout << setw(2) << " ";
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;
}
This program does not take in any screen inputs from the user.
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.