ex4_04.c

来自「[C语言入门经典(第4版)]整本书的源码!值得推荐!全部是最简单的源码!」· C语言 代码 · 共 31 行

C
31
字号
/*Exercise 4.1 Generate a multiplication table */
#include <stdio.h>

int main(void)
{
  int width = 0;                       /* Box width       */
  int height = 0;                      /* Box height      */

  printf("Enter the box width and height size separated by a space: ");
  scanf("%d", &width);
  scanf("%d", &height);

  for(int row = 0 ; row<height ; row++)
  {
    printf("\n");                      /* Start new row      */
    for(int col = 0 ; col<width ; col++)
    {
      if(row == 0||row==height-1)      /* 1st or last row?    */
      {
          printf("*");                 /* Yes - all asterisks */
          continue;
      }
      /* An * in 1st & last column, otherwise a space */
      printf("%c", ((col==0 || col==width-1) ? '*' :' '));
    }
  }
  printf("\n");
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?