我想打印下面的圖案,用戶輸入n和m(4和6)時,外面應該是星星,裏面應該填滿圓。如何在C中打印多個星形圖案的方格?
****** ****** ****** ******
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
****** ****** ****** ******
****** ****** ****** ******
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
****** ****** ****** ******
****** ****** ****** ******
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
****** ****** ****** ******
****** ****** ****** ******
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
****** ****** ****** ******
****** ****** ****** ******
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
****** ****** ****** ******
****** ****** ****** ******
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
*oooo* *oooo* *oooo* *oooo*
****** ****** ****** ******
我只能使用此代碼打印此代碼。我做錯了什麼?
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int n,i,j,k,m,n1;
printf("enter table size and enter square size");
scanf("%d %d", &n, &n1);
for (i = 0; i < n; i++) {
for (j = 0; j < n1; j++)
{
for (k = 0; k < n; k++)
{
for (m = 0; m < n1; m++)
{
{
if(i==0 || i==n-1)
{
printf("*");
}
else if(j==0 || j==n-1)
{
printf("*");
}
else
{
printf("o");
}
}
}
printf(" ");
}
printf("\n");
}
printf("\n");
}
system("pause");
return 0;
}
你卡在了什麼?有一個具體的問題? – Qix 2014-10-27 04:05:57
我認爲,mitt634,你卡在輸出中。你不能只打印一個正方形,然後像你想要的那樣打印其他人。你必須打印第一行,然後是第二行等。 – yulian 2014-10-27 04:08:25
你到底意味着什麼? *「如果用戶輸入n = 3,就像6個方格的星星。」*(看起來與9個印刷方塊「3x3」不符) – yulian 2014-10-27 05:19:16