首页 > 代码库 > 一个变量的九九乘法表(赞)
一个变量的九九乘法表(赞)
今天看到一个帖子:
说要求只用一个变量来做出来九九乘法表。。。
看到一楼的回复,表示呆了。。。神人无处不在:
但是,往后看就发现了一个真正的神人= =。:
#include <stdio.h> #include <stdlib.h> int main(void) { int a; for (a = 0x11; a < 0xa0; a++) { for (a = (a & 0xf0) + 1; (a & 0x0f) <= ((a & 0xf0) >> 4); a++) { printf("%dx%d=%d\t", (a & 0x0f), (a & 0xf0) >> 4, ((a & 0xf0) >> 4) * (a & 0x0f)); } a += 0x10; printf("\n"); } return 0; }
表示看了好久,才在YM提示下看懂。。。后来又看到一个人,想来这种方法是最正常的答案了把:
#include <stdio.h> int main() { for(int i=0;i<81;++i) { if((i/9+1)>=((i%9)+1)) printf("%d*%d=%2d ",(i/9)+1,(i%9)+1,((i/9)+1)*((i%9)+1)); if( i%9 == 8) printf("\n"); } return 0; }
当然还有各种解法:
void main() { for(int i=0;i<10;i++) { printf("%d x 1 = %d ", i, i); if(i>1) { printf("%d x 2 = %d ", i, i*2); if(i>2) { printf("%d x 3 = %d ", i, i*3); if(i>3) { printf("%d x 4 = %d ", i, i*4); if(i>4) { printf("%d x 5 = %d ", i, i*5); if(i>5) { printf("%d x 6 = %d ", i, i*6); if(i>6) { printf("%d x 7 = %d ", i, i*7); if(i>7) { printf("%d x 8 = %d ", i, i*8); if(i>8) { printf("%d x 9 = %d ", i, i*9); } } } } } } } } } }
一个变量的九九乘法表(赞)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。