2_3.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:1k
源码类别:

文章/文档

开发平台:

C/C++

  1. #include <iostream.h>
  2. void trgl(unsigned int);      //(正三角)
  3. void re_trgl(unsigned int);   //(反三角)
  4. void main()
  5. {
  6. unsigned int k;
  7. cout<<"请输入要打印的行数:";
  8. cin>>k;
  9. trgl(k);
  10. //cout<<endl;
  11. re_trgl(k);
  12. }
  13. void trgl(unsigned int n)    //(正三角)
  14. {
  15. unsigned i,j;
  16. for (i=1;i<=n;i++)
  17. {
  18. for (j=1;j<(n-i+1);j++)
  19. cout<<' ';
  20. for (j=1;j<=(2*i-1);j++)
  21. cout<<'*';
  22. cout<<endl;
  23. }
  24. }
  25. void re_trgl(unsigned int n)    //(反三角)
  26. {
  27. unsigned i,j;
  28. for (i=1;i<=n;i++)
  29. {
  30. for (j=1;j<=(i-1);j++)
  31. cout<<' ';
  32. for (j=1;j<=(2*(n-i)+1);j++)
  33. cout<<'*';
  34. cout<<endl;
  35. }
  36. }