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

[求助]如何做一个成法口诀表~

LiveGood 发布于 2007-05-22 23:18, 1981 次点击
做好后的效果是:


1*1=1
1*2=2 2*2=4
1*3=3 2*3=6
1*4=4 2*4=8
1*5=5 2*5=10
1*6=6 2*6=12 ......
1*7=7 2*7=14
1*8=8 2*8=16
1*9=9 2*9=18 9*9=81



[此贴子已经被作者于2007-5-22 23:18:55编辑过]

19 回复
#2
leeco2007-05-22 23:26

有人问过这个问题了


#include <stdio.h>


void fun2(int n,int k)
{
    if(k){
        fun2(n,k-1);
        printf(\"%d*%d=%d \",k,n,k*n);
    }
}


void fun1(int n)
{
    if(n){
        fun1(n-1);
        fun2(n,n);
        putchar('\n');
    }
}


int main()
{
    fun1(9);
}


#3
kisscjy2007-05-22 23:37

代码如下:

#include<iostream>
using namespace std;

void print(int n)
{
if(n!=1)
{
for(int i=1;i<=n;i++)
{
cout<<i<<"*"<<n<<"="<<i*n<<'\t';
}
cout<<endl;
print (n-1);
}
if(n==1) cout<<"1*1=1"<<endl;
}

void main()
{
int n=9;
print(n);

}

#4
aipb20072007-05-23 09:12

再来个版本:

[CODE]#include <iostream>
using namespace std;
int main(){
for(int i = 1;i < 10;++i){
for(int j = 1;j <= i;++j)
cout << i << "*" << j << "=" << i*j << " ";
cout << endl;
}
system("pause");
}[/CODE]

#5
孤魂居士2007-05-23 17:43
  怎么一个比一个简单??
#6
LiveGood2007-05-23 18:21
谢谢~
#7
yuziguang2007-05-24 07:48
4楼这位兄弟的程序代码确实很简单 ,但我去运行后发现了一个小小的问题 ~~~~
可稍作调整:
#include<iostream.h>
void main()
{
for(int i=1;i<10;i++)
{
for(int j=1;j<i;j++)
cout<<j<<"*"<<i<<"="<<j*i<<" ";
cout<<endl;
}
}
#8
aipb20072007-05-24 08:57
回复:(yuziguang) 4楼这位兄弟的程序代码确实很简...


确实,THANKS!
#9
zkkpkk2007-05-24 09:45
两层循环,外层换行
#10
neverDie2007-05-24 11:30
高!
#11
寒林孤鹰2007-05-25 20:33
前面兄弟的们的程序是简单,但是还是有很多不足的地方,比如7楼的兄弟,你的那个就没有有两数相等的时候的乘积,比如没有1*1,2*2,甚至9*9=?都没显示,漏掉了很多。现在把我的发上:
#include<iostream>
#include<iomanip>
#include<cctype>
using namespace std;
int main()
{
int table=0;
const int table_min=2;
const int table_max=12;
char ch=0;
do{
cout<<"what size table would you like ("<<table_min<<"to"<<table_max<<")?";
cin>>table;
cout<<endl;
if(table<table_min||table>table_max){
cout<<"Invalid table size entered.program terminated."<<endl;
exit(1);
}
cout<<" |";
for(int i=1;i<=table;i++)
cout<<" "<<setw(3)<<i<<" |"<<endl;
for(int i=0;i<=table;i++)
cout<<"------"<<endl;
for(int i=1;i<=table;i++)
{
cout<<" "<<setw(3)<<i<<" |";
for(int j=1;j<=table;j++)
cout<<" "<<setw(3)<<i*j<<" |"<<endl;
}
cout<<endl<<"do you want another table(y or n)?";
cin>>ch;
cout<<endl;
}while(std::tolower(ch)=='y');
return 0;
}
但是这个程序有个很奇怪的地方,在我的电脑上编译的时候对没什么错误,可是就是运行不了结果,各位兄弟去运行看看吧。。。。。。。。
#12
孤魂居士2007-05-25 20:37
  我还是觉得程序代码长点安全稳定些``````
#13
aipb20072007-05-25 20:55
回复:(寒林孤鹰)前面兄弟的们的程序是简单,但是还...
程序并不是代码的组合,而是逻辑思维的体现,上面的几种方法都是很好的。
之所以简单是因为逻辑到位了,只需要这样。那个兄弟漏掉的部分是因为再改我代码时把条件弄错了。

没有看你的代码,但是,这个问题你用这么长的书写,说明两点:1,你的思路不清晰,或者复杂了;2,你对基本语法的掌握不好。

不能通过编译,说明有语法错误,能通过编译但是运行出错,说明有潜在的语法错误或者逻辑错误。
我更喜欢前者!
#14
zkkpkk2007-05-26 15:29
以下是引用寒林孤鹰在2007-5-25 20:33:41的发言:
前面兄弟的们的程序是简单,但是还是有很多不足的地方,比如7楼的兄弟,你的那个就没有有两数相等的时候的乘积,比如没有1*1,2*2,甚至9*9=?都没显示,漏掉了很多。现在把我的发上:
#include<iostream>
#include<iomanip>
#include<cctype>
using namespace std;
int main()
{
int table=0;
const int table_min=2;
const int table_max=12;
char ch=0;
do{
cout<<"what size table would you like ("<<table_min<<"to"<<table_max<<")?";
cin>>table;
cout<<endl;
if(table<table_min||table>table_max){
cout<<"Invalid table size entered.program terminated."<<endl;
exit(1);
}
cout<<" |";
for(int i=1;i<=table;i++)
cout<<" "<<setw(3)<<i<<" |"<<endl;
for(int i=0;i<=table;i++)
cout<<"------"<<endl;
for(int i=1;i<=table;i++)
{
cout<<" "<<setw(3)<<i<<" |";
for(int j=1;j<=table;j++)
cout<<" "<<setw(3)<<i*j<<" |"<<endl;
}
cout<<endl<<"do you want another table(y or n)?";
cin>>ch;
cout<<endl;
}while(std::tolower(ch)=='y');
return 0;
}
但是这个程序有个很奇怪的地方,在我的电脑上编译的时候对没什么错误,可是就是运行不了结果,各位兄弟去运行看看吧。。。。。。。。

第一次见到一个99乘法表如此兴师动众

#15
cilubutong2007-05-27 15:13
回复:(寒林孤鹰)前面兄弟的们的程序是简单,但是还...
这位大哥所言甚是!!!!
#16
QQ97996452007-05-27 21:42
各位兄弟为什么不把注解也放上去呢`?
#17
寒林孤鹰2007-05-28 17:18
呵呵。。。。。。我那个边之所以复杂了点,是因为要在程序输出的时候还要做一个表格,不过大家说的也有道理。程序应该更简单些。
#18
zkkpkk2007-05-28 22:02
以下是引用寒林孤鹰在2007-5-28 17:18:40的发言:
呵呵。。。。。。我那个边之所以复杂了点,是因为要在程序输出的时候还要做一个表格,不过大家说的也有道理。程序应该更简单些。

怪不得你还用流操纵算子

#19
xieriguo2007-05-29 16:02

我有问题想问四楼:
using namespace stp;




system("pause");的功能是如何实现的

#20
我很菜19872007-05-29 20:58
没有必要写那么复杂~
  呵~~没有
1