/*
*copyright (c) 2014,烟台大学计算机学院
*All rights reserved
*文件名称:cv.cpp
*作者:孙春红
*完成日期:2014年11月7日
*版本号:v1.0
*
*问题描述:根据main函数中对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=7; //n代表要输出的行数
int i;
//通过在下面的循环里调用printchs函数,输出右面的图
for(i=1; i<=n; ++i)
{
printchs(n-i,' ');
printchs(2*i-1, 64+i) ;
cout<<endl;
}
return 0;
}
运行结果:
知识点总结:
学会使用函数调用输出字母图
学习心得:
在经过编写调用的星型图时,代码基本差不多,不同的也是最难的是输出字母,因为一时想不起如何表达输出字母,在这个问题上纠结了很久,但是经过“兄弟”们的提醒,选择使用SCAULL型语句表示。