回复 楼主 liquan1989
void printf_rhombus_2(int rhombus_len)
{
char *p_space;
p_space = new char[2*rhombus_len];
char *p_char;
p_char = new char[2*rhombus_len];
unsigned int space_len,char_len,i;
char_len=2*rhombus_len-1;
for(i=0;i<char_len;i++)
{
p_char[i]='*';
}
p_char[char_len]='\0';
//std::cout<<"p_char:"<<p_char<<std::endl;
//std::cout<<"p_char:"<<p_char+3<<std::endl;
space_len=rhombus_len-1;
for(i=0;i<space_len;i++)
{
p_space[i]=' ';
}
p_space[space_len]='\0';
//std::cout<<"p_space:"<<p_space<<std::endl;
//std::cout<<"p_space:"<<p_space+3<<std::endl;
std::cout<<"---------------------------------------"<<std::endl;
for(i=0;i<char_len;i++)
{
std::cout<<(p_space+(space_len-abs(space_len-i)));
std::cout<<(p_char+(abs(char_len-(2*i+1))))<<std::endl;
}
std::cout<<"---------------------------------------"<<std::endl;
delete [] p_char;
delete [] p_space;
std::cout<<"end"<<std::endl;
}