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

結果圖:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章