注册 登录
编程论坛 C++教室

[求助]编程打印九九乘法表

谁与争疯 发布于 2007-04-26 23:36, 7657 次点击
* 1 2 3 4 5 6 7 8 9
------------------------------------------------
1 1 2 3 4 5 6 7 8 9
2 2 4 3 8 10 12 14 16 18
3 3 6 9 12 15 18 21 24 27
4 ...
5...
...
9 9 18 27 36 45 36 63 72 81



要打印如上型状,请问如何实现算法?
14 回复
#2
谁与争疯2007-04-26 23:36
即,行和列的相交点,为得数
#3
markshao19862007-04-27 07:34

#include "stdafx.h"
#include <iostream>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[])
{
cout<<setfill(' ');
cout<<"*";
for(int i=1;i<10;i++)
cout<<setw(4)<<i;
cout<<'\n';
for (i=0;i<10;i++)
cout<<setw(4)<<"----";
cout<<'\n';
for(i=1;i<10;i++)
{
cout<<i;
for(int j=1;j<10;j++)
cout<<setw(4)<<i*j;
cout<<'\n';
}

return 0;
}

#4
bill88882007-04-27 12:35

就用几个循环就OK了
楼主最好是自己好好想想,比较简单的

#5
I喜欢c2007-04-27 12:37
两个for循环就ok...

前两排直接打印...
for(i=1;i<10;i++)
{
cout<<i<<' ';
for(j=1;j<10;j++)
cout<<i*j<<' '
cout<<endl;
}

[此贴子已经被作者于2007-4-27 20:23:21编辑过]

#6
I喜欢c2007-04-27 20:34



你有点像...

#7
谁与争疯2007-04-28 12:54

两个for循环?这样能搞定?不相信。。。

#8
谁与争疯2007-04-28 12:55
3楼兄弟的程序,在VC6中运行,提示出错啊?
#9
谁与争疯2007-04-28 12:57

fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
Error executing cl.exe.

Cpp1.exe - 1 error(s), 0 warning(s)

#10
I喜欢c2007-04-28 16:25
以下是引用谁与争疯在2007-4-28 12:54:23的发言:

两个for循环?这样能搞定?不相信。。。

#include<iostream>
#include<string.h>
#include <iomanip>
using namespace std;
int main()
{
int i,j;
cout<<"* 1 2 3 4 5 6 7 8 9"<<endl;
cout<<"-----------------------------"<<endl;
for(i=1;i<10;i++)
{
cout<<i;
for(j=1;j<10;j++)
cout<<setw(3)<<i*j;
cout<<endl;
}
getchar();
return 0;

}

dev-c++ 通过...
为什么不行?

#11
小猪笨笨2007-04-28 17:31

#include <iostream.h>
#include <iomanip.h>

int main()
{
int i,j;
cout<<*;
for(i=1;i<10;i++)
cout<<setw(4)<<i;
cout<<endl;

cout<<"--------------------------";

for(i=1;1<10;i++)
{
cout<<setw(4)<<i;
for(j=1;j<10;j++)
cout<<setw(4)<<(i*j);
cout<<endl;
}
return 0;
}

#12
小猪笨笨2007-04-28 17:32

靠 上面那句 cout<<"--------------------------";
改成 cout<<"--------------------------"<<endl;

低级错误。。。

1