使用for迴圈
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    //定義一個整數變數
    int i = 1 , j = 1 , product = 1;

    for( i = 1 ; i < 10 ; i++){
        //i * j = product
        for( j = 1 ; j < 10 ; j++){
         product = i * j ;
         cout << " " << i;
         cout << "*" << j ;
         //如果 product < 10 則多加1個空格!!!
         if( product < 10 ) cout << "= " << product ;
         else cout << "=" << product ;
        }
        cout << endl;
    }
    return 0;
    system("pause");
}

---------------------------------------------------------

使用do-while迴圈(包一個for迴圈)

#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    //定義一個整數變數
    int i = 1 , j = 1 , product = 1;

    do{
        //i * j = product
        for( j = 1 ; j < 10 ; j++){
          product = i * j ;
          cout << " " << i;
          cout << "*" << j ;
          //如果 product < 10 多加1個空格
          if( product < 10 ) cout << "= " << product ;
          else cout << "=" << product ;
        }
        cout << endl;
        i++;
    } while ( i < 10 );
    return 0;
    system("pause");
}

----------------------------------------------------------------------

使用雙重do-while迴圈

#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    //定義一個整數變數
    int multiplicand = 1 ,  product = 1;
    //multiplicand * multiplier = product
    do{
       int  multiplier = 1;//重點!!!!!!
       do{
          product = multiplicand * multiplier ;
          cout << " " << multiplicand;
          cout << "*" << multiplier ;
          //如果 product < 10 多加1個空格
          if( product < 10 ) cout << "= " << product ;
          else cout << "=" << product ;
          multiplier++;
        }while ( multiplier < 10 );
        cout << endl;
        multiplicand++;
    }while ( multiplicand < 10 );
    return 0;
    system("pause");
}
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 檸檬 的頭像
    檸檬

    檸檬的C語言初學日誌

    檸檬 發表在 痞客邦 留言(0) 人氣()