第11周项目1函数版星号图(2&review)
2014-11-06 14:35
260 查看
问题及代码:
运行结果:
问题及代码:
运行结果:
知识点总结:
对printchs函数的调用,以及printchs的功能要求,编写printchs函数。
学习心得:
想想上上个周写那个星号图的代码好纠结好惆怅。。果然知识就是力量,现在学了这玩意儿,还用怕啥星号图?!
<pre class="cpp" name="code">/* *Copyright (c)2014,烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:star.cpp *作 者:单昕昕 *完成日期:2014年11月6日 *版 本 号:v1.0 * *问题描述:根据main函数中对printchs函数的调用,以及printchs的功能要求,编写printchs函数。 *程序输出:星号图 */ #include <iostream> using namespace std; void printchs(int m,char ch) //定义能输出一行若干个指定字符的函数。 { for(int j=1;j<=m;++j) cout<<ch; } int main() { int n=6,i; //n代表要输出的行数。 for(i=1; i<=n; ++i) { printchs(n-i,' '); //调用函数,括号里为自定义输出的*数量。 printchs(2*i-1,'*'); cout<<endl; } return 0; }
运行结果:
问题及代码:
/* *Copyright (c)2014,烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:star.cpp *作 者:单昕昕 *完成日期:2014年11月6日 *版 本 号:v1.0 * *问题描述:调用函数输出星号图,体会与理解函数的工作过程,并为其后编制自定义函数实现特定功能。 *程序输出:星号图 */ #include <iostream> using namespace std; void printchs(int m,char ch) //定义能输出一行若干个指定字符的函数。 { for(int j=1;j<=m;++j) cout<<ch; } int main() { int n=10,i; //n代表要输出的行数。 for(i=1; i<=n; ++i) { printchs(n-i,'*'); //调用函数,括号里为自定义输出的*数量。 printchs(2*i-1,' '); cout<<endl; } return 0; }
运行结果:
知识点总结:
对printchs函数的调用,以及printchs的功能要求,编写printchs函数。
学习心得:
想想上上个周写那个星号图的代码好纠结好惆怅。。果然知识就是力量,现在学了这玩意儿,还用怕啥星号图?!
相关文章推荐
- 第11周项目1-函数版星号图(2)
- 第11周项目1函数版星号图(1)
- 第11周项目1-函数版星号图(3)输出字母三角形
- 第11周项目一 函数版星号图(1)
- 第11周项目1 函数版星号图(2printchs函数的调用)
- 第11周项目1-函数版星号图(3)
- 第11周项目1-函数版星号图(1)
- 第11周项目一 函数版星号图(3)
- 第11周项目1-函数版星号图(2)调用printchs函数
- 第11周项目1-函数版星号图(1)
- 第11周项目1函数版星号图(1填充程序输出星号图)
- 第11周项目1(2)-函数版星号图
- 第11周项目1函数版星号图(1)
- 第11周项目一 函数版星号图(2)
- 第11周项目1(1)-函数版星号图
- 第11周函数的定义与调用项目1 调用函数输出星号图
- 第11周 项目1 函数版星号图(1)(4)
- 第11周项目1函数版星号图
- 第11周项目一 函数版星号图(4)
- 第11周项目1函数星号图(2)