編寫有字符型參數c和整型參數N的函數,讓它顯示出由字符c組成的三角形。其方式為第1行有一個字符c,第2行有2個字符c等等-簡單


源程序:

#include < iostream >

using namespace std;

void print_triangle(char c, int n)

{

  int i, j;

  for (i = 0; i< n; i++)

  {

    for (j = 0; j <= i; j++)

    {

      cout << c;

    }

    cout << endl;

  }

}

void main()

{

  print_triangle('a', 10);

  system("pause");

}

 運行結果:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM