第11周專案2 編寫printchs函式
阿新 • • 發佈:2019-02-16
/*
*Copyright (c)2013,煙臺大學計算機學院
*All rights reserved.
*檔名稱:test.cpp
*作者:孫玲倩
*完成日期:2013年11月5日
*版本號:v1.0
*問題描述:根據main函式中對printchs函式的呼叫,以及printchs的功能要求編寫printchs函式
*/
//呼叫函式printchs輸出星號圖 #include <iostream> using namespace std; //在下面寫printchs函式的定義,功能是輸出一行若干個指定字元 void printchs (int m ,char ch) { for (int j=1;j<=m;++j) cout<<ch; } int main( ) { int n=6; //n代表要輸出的行數 int i; //通過在下面的迴圈裡呼叫printchs函式,輸出右面的圖 for(i=1; i<=n; ++i) { printchs(n-i,' '); printchs(2*i-1,'*') ; cout<<endl; } return 0; }