7-20 打印九九口诀表
题目链接-7-20 打印九九口诀表

解题思路
模拟
- 双层循环即可,记得内外循环变量在乘法表里是反着的,主要注意输出格式
- 因为等号右边数字占4位、左对齐所以用
%-4d输出 puts()函数用来向标准输出设备(屏幕)输出字符串并换行,用法为puts(s);puts("");相当于printf("\n");- 具体操作见代码
附上代码
#include<bits/stdc++.h>
#define lowbit(x) (x &(-x))
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=1e5+5;
typedef long long ll;
typedef pair<int,int> PII;
int main(){
int n;
scanf("%d",&n);
//格式a*b=c
for(int i=1;i<=n;i++){//枚举每一行的b
for(int j=1;j<=i;j++){//枚举每一行的a
printf("%d*%d=%-4d",j,i,i*j);
}
puts("");
}
return 0;
}
本文介绍了一种使用C语言打印九九乘法表的方法。通过双层循环结构,实现了从1到n的乘法表输出,注重输出格式的规范性。文章提供了完整的代码示例,包括必要的注释,帮助读者理解实现细节。
2352

被折叠的 条评论
为什么被折叠?



