概述
#include
#include
int isEven(int number);
void printLovingHeart(int number,int left);//打印爱心
void printUpLovingHeart(int number,int left);//打印爱心的上半部分
void printDownTri(int number, int left);//打印边长为number的向下正三角形,左边空left列
void printLovingHeartRow(int number, int row, int left);
void printRow(int number, int row, int left);
int main(){
int number;
while (fflush(stdin), scanf("%d", &number) != EOF){
if (isEven(number))
printLovingHeart(number,0);
else
printf("Please input a even number.n");
}
system("pause");
return 0;
}
int isEven(int number){
if (number % 2 == 0)
return 1;
else
return 0;
}
void printDownTri(int number, int left){
for (int i = number; i > 0; --i){//i为当前行*数
printRow(number, i, left);
printf("n");
}
}
void printUpLovingHeart(int number,int left){
for (int i = 2; i < number/2; ++i)//i为当前行
printLovingHeartRow(number, i, left);
}
void printLovingHeartRow(int number, int row, int left){
printRow(number/2-1,row,left+1);
printRow(number/2-1,row,number/2-row+2);
printf("n");
}
void printRow(int number, int row, int left){
for (int j = 0; j < left; ++j)//打印空列
printf(" ");
for (int j = 0; j < number - row; ++j)//打印左方空白
printf(" ");
for (int j = 0; j < row; ++j)//打印三角形的一行
printf("* ");
printf("b");
}
void printLovingHeart(int number,int left){
printUpLovingHeart(number,left);
printDownTri(number,left);
}
最后
以上就是重要月饼为你收集整理的c++打印心形_打印心形的全部内容,希望文章能够帮你解决c++打印心形_打印心形所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复