请高手帮忙编个c++的小程序。

来源:百度知道 编辑:UC知道 时间:2024/06/23 18:18:09
要求如下:
Write a program to print blocks of characters

Sample 1:
Enter two characters and an integer: $ * 3

$*$
*$*
$*$

Sample 2:

Enter two characters and an integer: * $ 4
*$*$
$*$*
*$*$
$*$*

Sample 3:

Enter two characters and an integer: / \ 6

/\/\/\
\/\/\/
/\/\/\
\/\/\/
/\/\/\
\/\/\/

#include<iostream>
using namespace std;
void main()
{
char str1,str2;
int count;
cout<<"input the two strings and the count:"<<endl;
cin>>str1>>str2>>count;
for(int i=0;i<count;i++)
{
for(int j=0;j<count;j++)
{
if(j%2==0)
cout<<str1;
else
cout<<str2;
}
cout<<endl;
}
}

#include "iostream"
using namespace std ;
void main()
{
int i=0,j=0,k=0;
char ch[2];
cout<<"please input two chars"<<endl;
for (i=0;i<2;i++)
cin>>ch[i];
cout<<"please input an integer"<<endl;
cin>>k;
for (i=0;i<k;i++)
{
for (j=0;j<k;j++)
cout<<ch[(j+i)%2];
cout<<endl;
}
}