作者在 2011-07-01 14:40:34 发布以下内容
1:#include<iostream>using namespace std;int main(){ int i,j,k,n;cout<<"请输入n的值:";cin>>n;for (i=1;i<=n;i++){if (i<=n/2){for (j=1;j<=n/2+1-i;j++)cout<<" ";for (k=1;k<=2*i-1;k++)cout<<"*";cout<<endl;}else{for (j=1;j<=i-n/2-1;j++)cout<<" ";for (k=1;k<=(2*(n-i)+1);k++)cout<<"*";cout<<endl;}}system("pause");return 0;}2:#include<iostream>using namespace std;int main(){ int i,j,k,n,m;cout<<"请输入n的值:";cin>>n;for (i=1;i<=n;i++){for (j=1;j<=n-i;j++)cout<<" ";for (k=1;k<=i;k++)cout<<"*";cout<<" ";for (m=1;m<=i;m++)cout<<"&";cout<<endl;}system("pause");return 0;}/*请输入n的值:10* &** &&*** &&&**** &&&&***** &&&&&****** &&&&&&******* &&&&&&&******** &&&&&&&&********* &&&&&&&&&********** &&&&&&&&&&3:#include<iostream>#include<iomanip>using namespace std;int main(){ int i,j,k,n;cout<<"请输入n的值:"<<endl;cin>>n;for (i=1;i<=n;i++){if (i<=n/2){for (j=1;j<=n/2+1-i;j++)cout<<setw(4)<<" ";for (k=1;k<=2*i-1;k++)cout<<setw(4)<<"*";cout<<endl;}else{for (j=1;j<=i-n/2-1;j++)cout<<setw(4)<<" ";for (k=1;k<=2*(n-i)+1;k++)cout<<setw(4)<<"*";cout<<endl;}}system("pause");return 0;}请输入n的值:9** * ** * * * ** * * * * * ** * * * * * * * ** * * * * * ** * * * ** * **4:#include<iostream>using namespace std;int main(){ int i,j,k,n;cout<<"请输入n的值:"<<endl;cin>>n;for (i=1;i<=n;i++){for (j=1;j<=n-i;j++)cout<<" ";for (k=1;k<=2*i-1;k++)cout<<char('A'+i-1);cout<<endl;}system("pause");return 0;}/*请输入n的值:10ABBBCCCCCDDDDDDDEEEEEEEEEFFFFFFFFFFFGGGGGGGGGGGGGHHHHHHHHHHHHHHHIIIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJJJJ5:#include<iostream>using namespace std;int main(){ int n,i,j,k;cout<<"请输入n的值:"<<endl;cin>>n;for(i=1;i<=n;i++){for(j=i;j>0;j--)cout<<"*";for(k=0;k<=2*(n-i);k++)cout<<" ";for(j=i;j>0;j--)cout<<"*";cout<<endl;}system("pause");return 0;}请输入n的值:7* *** ***** ******* ********* *********** ************* *******6:#include<iostream>#include<math>using namespace std;int main(){ int i,j,n;cout<<"请输入n的值:"<<endl;cin>>n;for (i=1;i<=n;i++){cout<<i<<'\t';for (j=1;j<=n+1;j++)cout<<fabs(j-i)<<'\t';cout<<endl;}system("pause");return 0;}/*请输入n的值:61 0 1 2 3 4 5 62 1 0 1 2 3 4 53 2 1 0 1 2 3 44 3 2 1 0 1 2 35 4 3 2 1 0 1 26 5 4 3 2 1 0 1*/7:#include<iostream>#include<iomanip>using namespace std;int fact(int n);int com(int m,int r);int main(){ int i,k,n,j;cout<<"请输入n的值:";cin>>n;for (i=1;i<=n;i++){ for (j=1;j<=n-i;j++)cout<<setw(2)<<" ";for (k=0;k<=i-1;k++)cout<<setw(4)<<com((i-1),k);cout<<endl;}system("pause");return 0;}int fact(int n){ int i,j=1;for (i=1;i<=n;i++)j*=i;return (j);}int com(int m,int r){ int y;y=fact(m)/(fact(r)*fact(m-r));return (y);}/*请输入n的值:1011 11 2 11 3 3 11 4 6 4 11 5 10 10 5 11 6 15 20 15 6 11 7 21 35 35 21 7 11 8 28 56 70 56 28 8 11 9 36 84 126 126 84 36 9 1*/