根据main函数中对printchs函数的调用,以及printchs的功能要求,编写printchs函数,使下面的程序能输出星号图:
来源:互联网 发布:java编码哪个是中文的 编辑:程序博客网 时间:2024/06/07 07:07
任务和代码:根据main函数中对printchs函数的调用,以及printchs的功能要求,编写printchs函数,使下面的程序能输出星号图。
/*文件名:main.c作者:小风景完成日期:2016.6.19问题描述:根据main函数中对printchs函数的调用,以及printchs的功能要求,编写printchs函数,使下面的程序能输出星号图:程序输出:星号图*/#include <stdio.h>void printchs(int m,char n) //定义能输出一行m个空格和n个星号的函数{ int j; for (j=1; j<=m; ++j) printf("%c",n);}int main( ){ int n=6; //n代表要输出的行数 int i; //通过在下面的循环里调用printchs函数,输出右面的图 for(i=1; i<=n; ++i) { printchs(n-i,' '); printchs(2*i-1,'*') ; printf("\n"); } return 0;}
程序运行截图:
在上面程序中,只修改一处,输出下面图形:
/*文件名:main.c作者:小风景完成日期:2016.6.19问题描述:根据main函数中对printchs函数的调用,以及printchs的功能要求,编写printchs函数,使下面的程序能输出星号图:程序输出:星号图*/#include <stdio.h>void printchs(int m,char n) //定义能输出一行m个空格和n个星号的函数{ int j; for (j=1; j<=m; ++j) printf("%c",n);}int main( ){ int n=6; //n代表要输出的行数 int i; //通过在下面的循环里调用printchs函数,输出右面的图 for(i=1; i<=n; ++i) { printchs(n-i,' '); printchs(2*i-1,'A' + i - 1) ; printf("\n"); } return 0;}
总结:通过观察输出的变化,在for语句中,空格输出不变,只变化第二次调用printfchs()传入的参数,ABCDEF之间的关系是渐次加1,因此改变第二个函数调用的第二个参数为'A'+i-1
0 0
- 根据main函数中对printchs函数的调用,以及printchs的功能要求,编写printchs函数,使下面的程序能输出星号图:
- 根据main函数中对printchs函数的调用,以及printchs的功能要求,编写printchs函数
- 第十一周 根据man函数中对printchs函数的调用,以及printchs的功能要求,编写printchs函数
- 调用函数printchs输出星号图
- 调用函数printchs输出星号图
- 调用函数printchs输出星号图。
- 调用函数printchs输出星号图
- 第11周项目1(2)-printchs函数的调用(输出星号图)
- 调用函数printchs递增星号图
- 调用函数printchs输出星号图(2)
- 调用函数printchs输出锥形递增星号图
- 调用printchs函数输出星号图
- 第11周项目1 函数版星号图(2printchs函数的调用)
- 编写printchs函数
- 第11周项目1-4用printchs函数输出学过的星号图
- 编程:函数版星号图 printchs函数
- 第十一周项目1——printchs函数的编写
- 第十一周项目1-(printchs函数的调用
- VS”不能设置下面断点“和”无法单步执行“问题
- table标签,认识网页上的表格
- java基础知识:栈内存和堆内存
- Android 四大组件的工作过程
- 杭电2069之Coin Change
- 根据main函数中对printchs函数的调用,以及printchs的功能要求,编写printchs函数,使下面的程序能输出星号图:
- Android MVP模式
- 用css样式,为表格加入边框
- 关于volatile关键字
- leetcode_c++:Missing Number(268)
- dagger2深入学习
- Greenplum或DeepGreen的管理数据
- 准备 LVM Volume Provider - 每天5分钟玩转 OpenStack(49)
- 队列和栈简单实现