图形输出程序总结
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的值:
10
A
BBB
CCCCC
DDDDDDD
EEEEEEEEE
FFFFFFFFFFF
GGGGGGGGGGGGG
HHHHHHHHHHHHHHH
IIIIIIIIIIIIIIIII
JJJJJJJJJJJJJJJJJJJ
5:
#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的值:
6
1 0 1 2 3 4 5 6
2 1 0 1 2 3 4 5
3 2 1 0 1 2 3 4
4 3 2 1 0 1 2 3
5 4 3 2 1 0 1 2
6 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的值:10
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
*/
|