c++难题,还请高手解答

来源:百度知道 编辑:UC知道 时间:2024/07/07 04:03:28
In this problem you need to make a multiply table of N * N ,just like the sample out. The element in the ith row and jth column should be the product(乘积) of i and j.

Input
The first line of input is an integer C which indicate the number of test cases.

Then C test cases follow.Each test case contains an integer N (1<=N<=9) in a line which mentioned above.

Output
For each test case, print out the multiply table.

Sample Input
2
1
4

Sample Output
1
1 2 3 4
2 4 6 8
3 6 9 12
4 8 12 16

HintThere is no blank space at the end of each line.

#include<iostream>

using namespace std;
void main()
{
int c,n,x,i,j;
while(cin>>c,c)
{
for(x=1;x<=c;x++)
{
cin>>n;
if(n<1||n>10)
break;

for(i=1;i<=n;i++)
{
for(j=1;j<n;j++)
cout<<i*j<<

题目的意思:
设有N*N的矩阵,设行为i,列为j,则矩阵形如:
i*j j*i j*i
i*j j*i j*i
i*j j*i j*i
输入:第一行为整型变量 C 代表有C组测试数据
接下来就是第一组测试数据 第二组测试数据........第C组测试数据
输出:矩阵

例子解释
输入:2 //有2组测试数据
1 //第一组测试数据
4 //第二组测试数据

输出:1 //第一组测试数据所对应的矩阵
1 2 3 4 //第二组测试数据所对应的矩阵
2 4 6 8
3 6 9 12
4 8 12 16

个人认为该代码有误,修改如下
代码
#include<iostream>
using namespace std;
int main() //设成有返回值的主函数
{
int c,n,x,i,j;
while(cin>>c,c)
{for(x=1;x<=c;x++)
{cin>>n;
if(n<1||n>10)
break;
for(i=1;i<=n;i++)
{for(j=1;j<n;j++)
cout<<i*j<<' ';
cout<<i*n<<endl;
}
}
}
return 0;//主函数值返回0
}

还有什么问题?

#include<iostream>
using namespa