2020-12-29

Cycle structure-use and share:
skin: how to use code to express love?
The characters printed by the for loop indicate:

#include<stdio.h>
int main()
{
    
    
	int n,i,j,k;
	printf("输个数,5<=x<=12:\n");
	scanf("%d",&n);
	printf("对!就这样:\n");
	printf("\n\n");
	for(i=1;i<=n;i++)
	{
    
    
		printf("       ");
		if(i==1)
		{
    
    
		for(j=1;j<n-2;j++)
		{
    
    
			printf("**");
		}
		}
		else if(i==n)
		{
    
    
			for(j=1;j<n-1;j++)
		printf("**");
		}
		else
		{
    
    for(j=1;j<n/2;j++)
			{
    
    	printf("  ");
			}
		}
			printf("**\n");
	}
	printf("\n\n");


for(i=2;i<=n;i++)
{
    
    
	
		for(j=1;j<=n-i;j++)
		{
    
    
			
			printf(" ");
		}
		printf("*");
		for(j=1;j<2*i-3;j++)
		{
    
    
			printf(" ");
		}
		printf("*");

	for(j=1;j<2*(n-i)+1;j++)
		{
    
    
			
			printf(" ");
		}
		printf("*");
		for(j=0;j<=2*i-5;j++)
		{
    
    
			printf(" ");
		}
		printf("*");
		printf("\n");
}

 for(i=1;i<n;i++)
   {
    
    
	  for(j=1;j<2*i+1;j++)
	{
    
    
		printf(" ");
	}
	printf("*");
	if(i==n-1)
	{
    
    printf("\n");
	break;}
	for(j=1;j<2*(2*(n-i))-4;j++)
	{
    
    
		printf(" ");
	}
	printf("*");
	printf("\n");
   }
printf("\n\n");
 




 for(i=1;i<=n;i++)
   {
    
    
printf("\n");
	if(i==n-1)
	{
    
      
		for(j=1;j<=n-1;j++)
		printf(" ");
		for(k=1;k<=n+1;k++)
	printf("* ");

	}

	else if(i==n)
		break;
	else
{
    
    
	  for(j=0;j<=n-2;j++)
	{
    
    
		printf(" ");
	}
	printf("*");

	for(j=0;j<2*n-1;j++)
	{
    
    
		printf(" ");
	}
	printf("*");
printf("\n");
	}

 }
printf("\n");
}

The output of the running result

is satisfactory but not beautiful. Hahaha, it is better to print it horizontally,
but the code printed horizontally is really hard to imagine (also the loop nesting of for), if you have ideas, you can share it!

Code analysis:
Each character is printed by nested for loops; the two character codes of I and U are very simple, so I won't repeat them here;
the code of the heart shape is derived from the following code for printing the diamond pattern:

#include<stdio.h>
int main()
{
    
    
	int i,j;
	int number;
	printf("请输入行数:");
	scanf("%d",&number);
	for(i=1;i<=number;i++)
{
    
    
		for(j=1;j<=number-i;j++)
		{
    
    
			
			printf(" ");
		}
		printf("*");
		
		if(i==1)
		{
    
    printf("\n");
		continue;
		}
		
		for(j=1;j<=2*i-3;j++)
		{
    
    
			printf(" ");
		}
		printf("*");
		printf("\n");
}
for(i=1;i<number;i++)
{
    
    	for(j=1;j<=i;j++)
	{
    
    
		printf(" ");
	}
	printf("*");
	if(i==number-1)
	{
    
    printf("\n");
	break;}
	for(j=1;j<=2*(number-i)-3;j++)
	{
    
    
		printf(" ");
	}
	printf("*");
	printf("\n");
}

	 return 0;
}
  **大致运行结果:**


It is obtained by filling and removing this code;

I've thought about using a for loop to print the initial capital letters of the name; it's better to type it horizontally. I really hope someone will share it.

Guess you like

Origin blog.csdn.net/yooppa/article/details/111913797