[此贴子已经被作者于2007-5-22 23:18:55编辑过]
有人问过这个问题了
#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);}
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);}
代码如下:#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);
}
再来个版本:[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]