您的位置:首页 > 编程语言 > C语言/C++

C++第七次上机实验

2016-06-05 19:47 465 查看
#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');
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: