输出一个矩形(长方形)

/*rectangle output with star*/
#include
int main()
{
  int length,width,x,y;//x horizotal axis;y vertical axis
  printf("Enter the length:");
  scanf("%d",&length);
  printf("Enter the width:");
  scanf("%d",&width);
  //for(x=1;x<=length;x++) printf("*");
  printf("\n");
  for(y=1;y<=width;y++)


  if   (y==1||y==width)  {{  for(x=1;x<=length;x++) printf("*");}printf("\n");  }
  else { for(x=1;x<=length;x++)
         {if(x==1||x==length) printf("*") ;
          else printf(" ");
         }
         printf("\n");
    }


  printf("\n");
return(0);

}



你可能感兴趣的:(C/C++学习)