问题及代码:
/*
*Copyringht (c) 2014,烟台大学计算机学院
*All right reserved.
*文件名称: test.cpp
*作 者:马明城
*完成日期:2014年11月9日
*版本号: v1.0
*问题描述:将程序补充完整,使其输出星号图
*输入描述:
*程序输出:将程序补充完整,使其输出星号图
*/
#include <iostream>
using namespace std;
void printstars(int m,int i)
{
for(int j=1;j<=m;++j)
cout<<'*';
}
int main()
{ int n=6,i;
for(i=1;i<=n;++i)
{
printstars(2*i-1,'*');
cout<<endl;
}
return 0;
}
运行结果:
知识总结:
这种自定义函数确实简单了许多。