C++打印乘法口诀表

C++打印乘法口诀表

tips:
用到了头文件 #include< iomanip > 中的功能setw(2) ,规定了第一个因数和乘积占的位数,这样让程序输出看起来更直观。
源代码:

#include<iostream>
#include<iomanip>
using namespace std;
int main(){
	
	int i,j;
	for(i=1;i<=9;i++){
		for(j=1;j<=i;j++)
			cout<<setw(2)<<i<<"*"<<j<<"="<<setw(2)<<i*j<<" ";
		cout<<endl;
	}
	
	return 0;
}

结果图:
在这里插入图片描述

发布了3 篇原创文章 · 获赞 0 · 访问量 23

猜你喜欢

转载自blog.csdn.net/zhaizhaizhaiaaa/article/details/103957743