欢迎来挑战:极限打印99乘法表

来源:互联网 发布:ubuntu win10启动项 编辑:程序博客网 时间:2024/05/01 11:53
#include <iostream>using namespace std;int main(){    //凡是有两个for,while循环的,有 if,有?:的,有Switch的全部Out!    int count = 1;    int sum = (1 + 9) * 9 / 2;    int flags = 1;    for (int i = 1; i <= sum; i++)    {        int n = i * 2 / flags - 1;        cout <<count<<"*"<<flags<<"="<<flags*count << " ";        (count == flags) && (count=0);        (count == 0) && (cout << endl);        (count == 0) && (flags++);        count++;    }    return 0;}

//下面是的第二种解法,要求依然是:
//凡是有两个for,while循环的,有 if,有?:的,有Switch的全部Out!

#include <iostream>using namespace std;int main(){    int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9};    int i = 0;    int j = 1;    int flags = 0;    for (; j<10;)    {        cout << a[i] << "*" << j << "=" << a[i] * j << " ";        i++;        (i == j) && (cout<<endl);        (i == j) && (flags++);        (i == j) && (j++);        (flags) && (i = 0);        (flags) && (flags = 0);    }    return 0;}

//此下面是我第三种递归解法。

#include <iostream>using namespace std; int fun(int x){    for (int i = 1; i <= 10 - x; i++)        cout << i << "*" << (10-x) << "=" << (10 - x)*i << " ";    cout << endl;    return !!(--x) && fun(x);}int main(){    fun(9);    return 0;}
1 0