#include <iostream.h>
void main()
{
int i,j,n,a[100][100];
char ch;
do
{
cout<<"\n\tPlease enter n(>2)=:";
cin>>n;
while(n<=2)
{
cout<<"\n\t\t\a\aInput Error!Please enter n(n>2)=";
cin>>n;
}
for(i=0;i<n;i++)
{
a[i][0]=1;
a[i][i]=1;
for(j=1;j<i;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j];
}
for(i=0;i<n;i++)
{
cout<<"\n";
for(j=0;j<2*(n-1)-2*i;j++)
cout<<" ";
for(j=0;j<i+1;j++)
{
if(a[i][j]<10)
cout<<a[i][j]<<" ";
else if(a[i][j]<100)
cout<<a[i][j]<<" ";
else
cout<<a[i][j]<<" ";
}
}
cout<<"\n\t\t\a\a是否继续做下一题? (y/n)";
cin>>ch;
while(!(ch=='n'||ch=='N'||ch=='y'||ch=='Y'))
{
cout<<"\n\t\t\a\aInput Error!Continue!?? (y/n)";
cin>>ch;
}
cin.ignore();
}while(ch=='y'||ch=='Y');
}
C++第七次上机实验
猜你喜欢
转载自blog.csdn.net/qq_34143673/article/details/51591045
今日推荐
周排行