int main() { int side; printf(“请输入正方形的边长:”); scanf(“%d”, &side); for (int i = 1; i <= side; i++) { for (int j = 1; j <= side; j++) { if (i == 1 || i == side || j == 1 || j == side) { printf("*"); } else { printf(" "); } } ...
思路:输出正方形即输出正方形的外围就行,外围有个特点就是行列下标必有0或者是正方形的大小减一,输入一个n表示正方形大小,输出一个由*组成的正方形。includestdio.hvoidmain(){intn,i;scanf(%d,&n);/*输入个数n*/for(i=1;i=n;i++)printf(*);/*循环输出字符*,若想修改显示格式...
if (x == 0 || y == 0 || x == num - 1 || y == num - 1) {//正方形的4条边,如果符合printf ("*");//打印*}else {//其他printf (" ");//打印空格}}}return 0;}另外一种方法:一行一行的输出1、输出n个*2、输出一个*,n-2个空格,一个*3、循环第二步n-2次4、输出n个* ...
#include<stdio.h> main() { int i,j,n; scanf("%d",&n); for(i=1;i<=n;...
include<stdio.h>int main(){int n;//正方形的边长int i,j;printf("请输入正方形的边长:\n");scanf("%d",&n);for(i = 1;i<=n;i++){for(j = 1;j<=n;j++){if(i == 1||i == n){printf("* ");}else{if(j == 1 || j == n){printf("* ");}else{printf(" ...
int main(){ int n;scanf("%d",&n);int i;for(i=0;i<n;i++){ printf("*");if(i==n-1){printf("\n");} } for(i=0;i<n-2;i++){ int x;for(x=0;x<n;x++){ if(x==0||x==n-1){printf("*");} else{printf(" ");} if(x==n-1){printf("\n");} ...