这个程序一直运行下去,会不会让人大吃一惊?
#include<iostream>
using namespace std;
void funA();
void funB();
void funA(){
cout<<"A";
funB();// 调用可能会优化成跳转,也许可以实现无限循环,这可是尾递归呀!
}
void funB(){
cout<<"B";
funA();// 调用可能会优化成跳转,也许可以实现无限循环,这可是尾递归呀!
}
int main(){
funA();
}
#include <iostream>
using std::cout;
using std::endl;
void mutiply_table(int a, int b)
{
cout << a << "*" << b << "=" << a*b << "\t";
if (1==a && 1==b)
{
return;
}
else if (a>=b && b>1)
{
mutiply_table(a, b-1);
}
else
{
if (1 == b)
{
cout << endl;
}
mutiply_table(a-1, a-1);
}
}
int main(int argc, char *argv[])
{
mutiply_table(9, 9);
return 0;
}