مثلث خیام به زبان ++C
#1
Note 
[تصویر:  PascalTriangleAnimated2.gif]
[CPP]
#include <iostream.h>
#include <conio.h>

int *charger(int *x, int *y)
{
for (int i = 1; i < 100; i++)
{
y[i] = x[i - 1] + x[i];
}
return y;
}

int main()
{
cout <<
"Welcome to Khayyam-Pascal Triangle Program.nThis program helps you to calculate Khayyam-Pascal Triangle." << endl;
int rows = 0;
int *a = new int[100];
int *b = new int[100];
for (int i = 0; i < 100; i++)
{
a[i] = 0;
b[i] = 0;
}
char answer = 'u';
error: cout << "Enter number of rows(max 34)" << endl;
cin >> rows;
if (rows > 34)
{
cout << "Error report: You have Entered a number bigger than 34." << endl;
cout << " This may make mistakes in program." << endl;
cout << " Would you like to enter another number?(y,n)" <<
endl;
cout << " ";
cin >> answer;
if (answer == 'y')
{
goto error;
}

}
a[1] = 1;
cout << "------------------Khayyam Pascal Triangle-------------------" <<
endl;
while (rows > 0)
{
for (int i = 1; i < 100; i++)
{
if (a[i] != 0)
cout << a[i] << " ";
else
break;
}
b = charger(a, b);
cout << endl;
rows--;
if (rows > 0)
{
for (int i = 1; i < 100; i++)
{
if (b[i] != 0)
cout << b[i] << " ";
else
break;
}
cout << endl;
rows--;
a = charger(b, a);
}
}


getch();
return 0;
}
[/CPP]

پاسخ
ایجاد موضوع جدید   پاسخ به موضوع  

کاربرانِ درحال بازدید از این موضوع:   1 مهمان