2_3.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:1k
- #include <iostream.h>
- void trgl(unsigned int); //(正三角)
- void re_trgl(unsigned int); //(反三角)
- void main()
- {
- unsigned int k;
- cout<<"请输入要打印的行数:";
- cin>>k;
- trgl(k);
- //cout<<endl;
- re_trgl(k);
- }
- void trgl(unsigned int n) //(正三角)
- {
- unsigned i,j;
- for (i=1;i<=n;i++)
- {
- for (j=1;j<(n-i+1);j++)
- cout<<' ';
- for (j=1;j<=(2*i-1);j++)
- cout<<'*';
- cout<<endl;
- }
- }
- void re_trgl(unsigned int n) //(反三角)
- {
- unsigned i,j;
- for (i=1;i<=n;i++)
- {
- for (j=1;j<=(i-1);j++)
- cout<<' ';
- for (j=1;j<=(2*(n-i)+1);j++)
- cout<<'*';
- cout<<endl;
- }
- }