第十一周 根据man函数中对printchs函数的调用,以及printchs的功能要求,编写printchs函数

本文展示了一个程序,它通过调用printchs函数来输出包含不同字符的行,实现了一种简单的文本布局效果。程序首先定义了printchs函数,用于输出指定数量的相同字符。然后在主函数中,利用此函数生成了包含空格和星号的对称图案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>
using namespace std;
#include <cstdio>
//在下面写printchs函数的定义,功能是输出一行若干个指定字符
 void printchs(int x,char ch)
 {int a;
    for(a=1;a<=x;a++)
     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;
}
</span></strong>

 

 

#include <iostream>
using namespace std;
void printchs(int x,char ch)
{
    int a;
    for(a=1; a<=x; a++)
        cout<<ch;
}
int main( )
{
    int n=6,i; //n代表要输出的行数
    for(i=1; i<=n; ++i)
    {

        printchs(n-i,' ');
        printchs(2*i-1,char(64+i)) ;
        cout<<endl;
    }
    return 0;
}


 

#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值