印出字母菱形出現亂碼
程式碼如下
程序代码:
#include<stdio.h>
int main()
{
int n;
char ch='A';
printf("Input :");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=0;j<(n-i);j++)
{
printf(" ");
}
for(int j=0;j<(i*2-1);j++)
{
printf("%2c",ch);
ch++;
if(ch=='Z'+1)
ch='a';
}
printf("\n");
}
for(int i=n-1;i>=1;i--)
{
for(int j=0;j<(n-i);j++)
{
printf(" ");
}
for(int j=0;j<(i*2-1);j++)
{
printf("%2c",ch);
ch++;
if(ch=='z'+1)
ch='A';
}
printf("\n");
}
}
輸出出現







