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;
}
結果圖: