c用‘*’画菱形可变大小
以下是用*输出一个菱形可通过longb的大小改变菱形的大小
#include<stdio.h>
static int x=1;
static int y=1;
static int numx1;
static int numx2;
static int longb=15;//菱形对角线长度可改变
static int temp;
extern void printfxingxing1(int longb);
extern void printfxingxing2(int longb);
extern void printfxingxing3(int longb);
void main()
{
printfxingxing1(longb);
printfxingxing2(longb);
printfxingxing3(longb);
}
void printfxingxing1(int longb)
{
temp=longb/3;
numx1=numx2=temp+longb/2+1;
for(y;y<=temp;y++)
{
for(x=0;x<=temp*4;x++)
{
if(x==numx1||x==numx2)
{
printf("*");
}else{
printf(" ");
}
}
numx1--;
numx2++;
printf("\n");
if(y==temp)
{
for(int i=1;i<=temp*4-2;i++)
{
if(i<=temp||i>=temp*3-1)
{
printf("* ");
}else
{
printf(" ");
}
}
printf("\n");
}
}
}
void printfxingxing2(int longb)
{
temp=longb/3;
numx1=2;
numx2=temp*5+1;
for(y=1;y<=temp-2;y++)
{
for(x=1;x<=temp*5+2;x++)
{
if(x==numx1||x==numx2)
{
printf("*");
}else{
printf(" ");
}
}
numx1=numx1+2;
numx2=numx2-2;
printf("\n");
}
}
void printfxingxing3(int longb)
{
temp=longb/3;
numx1=temp;
numx2=temp*4+3;
int num1,num2;
num1=num2=temp+longb/2+1;
for(y=1;y<=temp;y++)
{
for(x=1;x<=temp*6;x++)
{
if((x==numx1||x==numx2)||((x==num1||x==num2)&&y>=temp/2-1))
{
printf("*");
}else{
printf(" ");
}
}
numx1=numx1-1;
numx2=numx2+1;
num1=num1-3;
num2=num2+3;
printf("\n");
}
}