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;
}