⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex4_01.c

📁 [C语言入门经典(第4版)]整本书的源码!值得推荐!全部是最简单的源码!
💻 C
字号:
/*Exercise 4.1 Generate a multiplication table */
#include <stdio.h>

int main(void)
{
  int table_size = 0;                       /* Table size        */

  printf("Enter the table size (from 2 to 12): ");
  scanf("%d", &table_size);
  if(table_size>12)
  {
    printf("\nTable size must not exceed 12 - setting to 12");
    table_size = 12;
  }
  else if(table_size<2)
  {
    printf("\nTable size must be at least 2 - setting to 2");
    table_size = 2;
  }

  for(int row = 0 ; row<=table_size ; row++)
  {
    printf("\n");                      /* Start new row */
    for(int col = 0 ; col<=table_size ; col++)
    {
      if(row == 0)                     /* 1st row?                     */
      {                                /* Yes - output column headings */
        if(col == 0)                   /* 1st column?                  */
          printf("    ");              /* Yes - no heading             */
        else
          printf("|%4d", col);         /*No - output heading           */
      }
      else
      {                               /* Not 1st row - output rows     */
        if(col == 0)                  /* 1st column?                   */
          printf("%4d", row);         /* Yes - output row label        */
        else
          printf("|%4d", row*col);    /* No - output table entry       */
      }
    }
    if(row == 0 )                     /* If we just completed 1st row  */
    {                                 /* output separator dashes       */
      printf("\n");
      for(int col=0 ; col<=table_size ; col++)
        printf("_____");
    }
  }
  printf("\n");
	return 0;
}

⌨️ 快捷键说明

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