帮看下这道C++题怎么写啊,谢谢!!!
不知你的 E6.22是怎么声明的, 但它的意思就是重写这个函数,按照输入的边数及字符输出正方形
5 #
#####
#####
#####
#####
#####
4 @
@@@@
@@@@
@@@@
@@@@
上面运行结果,下面代码
#include <iostream>
using namespace std;
void myfill(int side, char fillCharacter);
int main(void)
{
int side = 0;
cin >> side;
char fillCharacter;
cin >> fillCharacter;
myfill(side, fillCharacter);
return 0;
}
void myfill(int side, char fillCharacter)
{
int k = side - 1;
for(int i = 0; i < side; ++i){
for(int j = 0; j < side; ++j){
cout << fillCharacter;
if(j == k){
cout << endl;
}
}
}
}
#include <iostream>
using namespace std;
void myfill(int side, char fillCharacter);
int main(void)
{
int side = 0;
cin >> side;
char fillCharacter;
cin >> fillCharacter;
myfill(side, fillCharacter);
return 0;
}
void myfill(int side, char fillCharacter)
{
int k = side - 1;
for(int i = 0; i < side; ++i){
for(int j = 0; j < side; ++j){
cout << fillCharacter;
if(j == k){
cout << endl;
}
}
}
}
622是要你有个函数固定用*来表示输出如下面写的, 然后上面那题就是扩展这622可以使用其它字符来表示输出如#
void myfill(int side)
{
int k = side - 1;
for(int i= 0; i < side; ++i){
for(int j = 0; j < side; ++j){
cout << '*';
}
cout << endl;
}
}
1
2
3
4
5
#include <stdio.h>
int main(void)
{
int num = 5;
printf("请输入字符个数\n");
scanf("%d", &num);
int ch = 0;
scanf("%d", &ch);
printf("请输入字符\n");
if(num<=0)
return -1;
for(int i=0; i<num; i++)
{
for(int j=0; j<num; j++)
{
printf("%c", ch);
}
printf("\n");
}
return 0;
}
using namespace std;
void main()
{
int side,i,j;
char fillchar;
cin>>side>>fillchar;
for(i=0;i<side;i++)
{for(j=0;j<side;j++)
cout<<fillchar;
cout<<endl;
}
}