您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

C程序表示乘法表

2024/3/11 20:20:15发布16次查看
问题编写一个程序,按照以下给定的格式打印从1 x 1到12 x 10的乘法表:
1 2 3 4 5 6 7 8 9 102 4 6 8 ……………….203 6 9…………………….304 8 12 16……………..40---12 24……………………..120
解决方案使用两个嵌套的do while循环来显示乘法表。
用于显示乘法表的逻辑如下:
内部循环由变量列控制,每当外部循环执行一次时,内部循环就会执行10次。
外部循环执行12次,由变量行控制。
do /*......outer loop begins........*/{ column = 1; do /*.......inner loop begins.......*/{ y = row * column; printf("%4d", y); column = column + 1; } while (column <= colmax); /*... inner loop ends ...*/ printf("
"); row = row + 1;}while (row <= rowmax);/*..... outer loop ends .....*/
示例以下是打印乘法表的c程序−
实时演示
#include<stdio.h>#define colmax 10#define rowmax 12main(){ int row,column, y; row = 1; printf(" multiplication table
"); printf("-----------------------------------------
"); do /*......outer loop begins........*/ { column = 1; do /*.......inner loop begins.......*/ { y = row * column; printf("%4d", y); column = column + 1; } while (column <= colmax); /*... inner loop ends ...*/ printf("
"); row = row + 1; } while (row <= rowmax);/*..... outer loop ends .....*/ printf("-----------------------------------------
");}
输出当上述程序执行时,它产生以下输出 −
multiplication table----------------------------------------- 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20 24 28 32 36 40 5 10 15 20 25 30 35 40 45 50 6 12 18 24 30 36 42 48 54 60 7 14 21 28 35 42 49 56 63 70 8 16 24 32 40 48 56 64 72 80 9 18 27 36 45 54 63 72 81 9010 20 30 40 50 60 70 80 90 10011 22 33 44 55 66 77 88 99 11012 24 36 48 60 72 84 96 108 120-----------------------------------------
以上就是c程序表示乘法表的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product