歡迎來挑戰:極限打印99乘法表

#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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章