(1)
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
cout<<setw(4)<<"*";
for(int i=1;i++;i<=9)
cout<<i<<endl;
/* for(int k=1;k++;i<=9)
{
cout<<k;
for(int j=1;j<=9;j++)
cout<<i*j;
cout<<endl;
}*/
}
(2)
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
cout<<setw(4)<<"*";
for(int i=1;i<=9;i++)
cout<<setw(4)<<i;
cout<<"\n...........................................\n";
for(int k=1;k<=9;k++)
{
cout<<setw(4)<<k;
for(int j=1;/*j<=9*/j<=k;j++)//将j<=9更改成j<=k即可
cout<<setw(4)<<k*j;
cout<<endl;
}
cout<<endl;
}
(3)
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
cout<<setw(4)<<"*";
for(int i=1;i<=9;i++)
cout<<setw(4)<<i;
cout<<"\n...........................................\n";
for(int k=1;k<=9;k++)
{
cout<<setw(4)<<k;
if(k!=1)
cout<<setw(4*k-4)<<" ";
for(int j=k;j<=9;j++)//此时,J从k开始循环
cout<<setw(4)<<k*j;
cout<<endl;
}
cout<<endl;
}
|