#include
int main()
{
int i,j,m,n;
char a[m][n];
printf("請輸入行和列:\n");
scanf("%d,%d",&i,&j);
printf("\n");
for(m=0;m<i;m++)
{
if(m==0||m==i-1)
for(n=0;n<j;n++)
a[m][n]='*';
else
for(n=0;n<j;n++)
{
if(n==0||n==j-1)
{
a[m][0]='*';
a[m][j-1]='*';
}
else a[m][n]=' ';
}
for(m=0;m<i;m++)
{
for(n=0;n<j;n++)
printf("%c",a[m][n]);
printf("\n");
}
}
return 0;
}
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int main()
{
int i, j;
char * a;
printf("please input\n");
scanf_s("%d,%d", &i, &j);
printf("\n");
a = new char[i*j];
for (int m = 0; m < i*j; m++)
a[m] = ' ';
for (int m = 0; m<i; m++)
{
if (m == 0 || m == i - 1)
for (int n = 0; n<j; n++)
a[m*j+n] = '*';
else
for (int n = 0; n<j; n++)
{
if (n == 0 || n == j - 1)
{
a[m*j] = '*';
a[m*j +j - 1] = '*';
}
else a[m*j+n] = ' ';
}
for (int m = 0; m<i; m++)
{
for (int n = 0; n<j; n++)
printf("%c", a[m*j + n]);
printf("\n");
}
}
return 0;
}
大概給你修改了下,VS2013運行通過