打印爱心
1.1:普通输出爱心
#include<stdio.h>
int main()
{
printf(" ********* *********\n"); //7(代表边上的空格)
printf(" *************** ***************\n"); //4
printf(" ****************** ******************\n");//2
printf(" ***************************************\n");//1
printf("*****************************************\n");//0
printf("*****************************************\n");//0
printf(" ***************************************\n");//1
printf(" *************************************\n");//2
printf(" **********************************\n");//4
printf(" *****************************\n");//6
printf(" *************************\n");//8
printf(" *******************\n");//11
printf(" *************\n");//14
printf(" *******\n");//17
printf(" ***\n");//19
return 0;
}
1.2循环打印爱心(效果自己实现观看)
#include<stdio.h>
int main()
{
int gui[15] = { 7,4,2,1,0,0,1,2,4,6,8,11,14,17,19 };// 输出每一行的空格数
int i = 0,j=0;
int zhonggui[3] = { 9,3,1 }; //输出中间的空格
int xing[3] = { 9,15,18 }; //输出中间的星号
for (i = 0; i < 3; i++)
{
for (j = 0; j < gui[i]; j++) putchar(' ');
for (j = 0; j < xing[i]; j++) putchar('*');
for (j = 0; j < zhonggui[i]; j++) putchar(' ');
for (j = 0; j < xing[i]; j++) putchar('*');
putchar('\n');
}
for (i = 3; i <15; i++)
{
for (j = 0; j < gui[i]; j++) putchar(' ');
for (j = 0; j < 41 - gui[i] * 2; j++) putchar('*');
putchar('\n');
}
getchar();
return 0;
}
2:符号变换爱心(这个还是不错的,有动态效果的样子)
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
char str[15][41] = {
" ********* ********* ",
" *************** *************** ",
" ****************** ****************** ",
" *************************************** ",
"*****************************************",
"*****************************************",
" *************************************** ",
" ************************************* ",
" ********************************* ",
" ***************************** ",
" ************************* ",
" ******************* ",
" ************* ",
" ******* ",
" *** ",
};
void Goto(int hang,int lie)
{
COORD cd = {lie,hang};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cd);
}
void Dong(int m,char c)
{
int n = 0;
while (n++ < 1000)
{
int hang = rand() % 15;
int lie = rand() % 41;
if ('*' != str[hang][lie])
continue;
Goto(hang, lie);
putchar(c);
Sleep(5);
}
}
int main()
{
srand((unsigned int)time(NULL));
Dong(300, '*');
Dong(500, '+');
Dong(200, '+');
return 0;
}
标签:练习题,lie,13,putchar,烧脑,int,++,printf,include
From: https://blog.csdn.net/weixin_52710247/article/details/139336900