C语言学习系列3-九九乘法表
来源:互联网 发布:华为万兆网络解决方案 编辑:程序博客网 时间:2024/06/14 16:47
C语言学习系列3-九九乘法表
操作环境:CentOS release 6.4 (Final)
编译环境:gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3)
新建文件 helloworld3.c,编辑保存如下内容:
#include<stdio.h> #include<stdlib.h> #include<string.h> int main(){ printf("九九乘法表如下\n"); int i; int j; for(i=1;i<=9;i++){ for(j=1;j<=9;j++){ if(j<=i){ printf("%d*%d=%d ", i,j,i*j); } } printf("\n"); } return 0; }
编译文件 helloworld3.c
gcc helloworld3.c -o helloworld3
执行查看效果
[root@mail temp]# ./helloworld3
九九乘法表如下
1*1=1
2*1=2 2*2=4
3*1=3 3*2=6 3*3=9
4*1=4 4*2=8 4*3=12 4*4=16
5*1=5 5*2=10 5*3=15 5*4=20 5*5=25
6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36
7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49
8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64
9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81
可以看到空格处列没有对齐,有没有办法呢,参见如下代码片即可解决
#include<stdio.h> #include<stdlib.h> #include<string.h> int main(){ printf("九九乘法表如下\n"); int i; int j; for(i=1;i<=9;i++){ for(j=1;j<=9;j++){ if(j<=i){ printf("%d*%d=%2d ", i,j,i*j); } } printf("\n"); } return 0; }
执行结果
九九乘法表如下
1*1= 1
2*1= 2 2*2= 4
3*1= 3 3*2= 6 3*3= 9
4*1= 4 4*2= 8 4*3=12 4*4=16
5*1= 5 5*2=10 5*3=15 5*4=20 5*5=25
6*1= 6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36
7*1= 7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49
8*1= 8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64
9*1= 9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81
- C语言学习系列3-九九乘法表
- C语言打印九九乘法表
- C语言-------九九乘法表
- c语言打印九九乘法表
- c语言输出九九乘法表
- C语言(九九乘法表)
- c语言编写九九乘法表
- c语言编写九九乘法表
- C语言打印九九乘法表
- C语言 九九乘法表
- C语言九九乘法表
- C语言打印九九乘法表
- C语言打印九九乘法表
- C语言实现---九九乘法表
- C语言 九九乘法表
- C语言基础 九九乘法表
- c语言打印九九乘法表
- <C语言>九九乘法表
- angularjs排序查找修改替换完整版
- webrtc中的rtp扩展 rtp-hdrext
- Android Studio 出现Frameworks detected:Android framework is detected in the project Configure
- Android学习-BroadcastReceiver
- arm-none-linux-gnueabi-g++: error trying to exec 'cc1plus': execvp: No such file or dictionary
- C语言学习系列3-九九乘法表
- 线程间通信的方式
- 特征脸(Eigenface)理论基础-PCA(主成分分析法)
- UVALive 7040 Color (容斥原理 + 组合数学递推公式 + 求逆元 + 基础数论)
- san
- 关于mysql从5.5升级至5.7的具体步骤
- AngularJS常见报错总结
- JAVA NIO Buffer的学习
- C# 字符串为空判断