首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

函数的有关问题

2012-02-04 
函数的问题?编写个函数,用于接收3到10之间的一个数,然后输出由星号组成的正方形。比如用户输入四:*********

函数的问题?
编写个函数,用于接收3到10之间的一个数,然后输出由星号组成的正方形。
比如用户输入四:
****
*     *
*     *
****

[解决办法]
#include <stdio.h>

void print(int count)
{
int i,j;
for(i=0;i <count;i++)
{
if(i==0||i==count-1)
{
for(j=0;j <count;j++)printf( "* ");
printf( "\n ");
}
else
{
for(j=0;j <count;j++)
{
if(j==0||j==count-1)printf( "* ");
else printf( " ");
}
printf( "\n ");
}
}
printf( "\n ");
}

int main()
{
int count;
scanf( "%d ",&count);
if(count <3)return 1;
print(count);

return 0;
}

热点排行