返回列表 發帖

[回家作業] 函數版 99乘法表

運用函數,自行寫99乘法表

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. double test(double a,double b)
  5. {
  6.         return a*b;
  7. }
  8. int main()
  9. {
  10.         int a=0,b=0;
  11.         cout<<"請輸入第一個數字"<<endl;
  12.         cin>>a;
  13.         cout<<"請輸入第二個數字"<<endl;
  14.         cin>>b;
  15.         for(int i=1;i<=a;i++)
  16.         {
  17.                 for(int j=1;j<=b;j++)
  18.                 {
  19.                   cout<<i<<"*"<<j<<"="<<test(a,b)<<"\t";       
  20.                 }
  21.         }
  22.         system("pause");
  23.         return 0;
  24. }
複製代碼

TOP

本帖最後由 吳秉翰 於 2018-6-9 13:54 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. void multi (int start,int end)
  5. {
  6.     for(int i=start;i<=end;i++)
  7.     {
  8.         for(int j=start;j<=end;j++)
  9.         {
  10.             cout<<i<<"*"<<j<<"="<<i*j<<endl;
  11.         }
  12.     }
  13. }
  14. int main()
  15. {
  16.     multi(1,9);
  17.     system("pause");
  18.     return 0;
  19. }
複製代碼

TOP

本帖最後由 戴嘉禾 於 2018-6-9 13:57 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. void test(int num,int num1)
  5. {

  6. for(int i=num;i<=num1;i++)
  7.    {
  8.     for(int j=num;j<=num1;j++)
  9.       {
  10.         cout<<i<<"*"<<j<<"="<<i*j<<endl;
  11.       }        
  12.    }     

  13. }
  14. int main()
  15. {
  16.     test(1,9);
  17.     system("pause");
  18.     return 0;
  19. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. void test(int a,int z)
  5. {
  6.       for(int i=a;i<=a;i++)
  7.       {
  8.         for(int j=z;j<=z;j++)
  9.         {
  10.         cout<<i<<"*"<<j<<"="<<i*j;        
  11.         }
  12.       }
  13. }
  14. int main()
  15. {
  16.      test(1,2);   
  17.      system("pause");
  18.      return 0;
  19. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. void test(int a ;int b )
  5. {
  6.     for(int i=a;i>=b;i++)   
  7.     {
  8.        for(int j=a;j>=b;j++)
  9.        {
  10.          cout<<i<<"*"<<j<<"="<<i*j<<endl;      
  11.        }  
  12.     }   
  13. }
  14. int main()
  15. {
  16.        test(1,9)
  17.         system("pause");
  18.         return 0;
  19. }
複製代碼

TOP

  1. #include <cstdlib>
  2. #include <iostream>
  3. using namespace std;
  4. void test(int start,int end)
  5. {
  6.      for(int i=start;i<=end;i++)
  7.      {
  8.              for(int j=start;j<=end;j++)
  9.              {
  10.                      cout<<i<<"*"<<j<<"="<<i*j<<"\t";
  11.              }
  12.              cout<<endl;
  13.      }
  14. }
  15. int main()
  16. {
  17.     int start=0;
  18.     int end=0;
  19.     cout<<"請輸入開始的數:";
  20.     cin>>start;
  21.     cout<<"請輸入結束的數:";
  22.     cin>>end;
  23.     test(start,end);
  24.     system("pause");
  25.     return 0;
  26. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. void test(int start,int end)
  5. {
  6.      for(int i=start;i <<end;i++ )
  7.      {
  8.       for(int j=start;j <<end;i++ )
  9.       {
  10.        cout<<i<<"*"<<j<<"="<<i*j<<endl;      
  11.               }
  12.        }
  13.        }   
  14. int main()
  15. {
  16.     system("pause");
  17.         return 0;
  18. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. void test(int num,int num1)
  5. {

  6. for(int i=num;i<=num1;i++)
  7.    {
  8.     for(int j=num;j<=num1;j++)
  9.       {
  10.         cout<<i<<"*"<<j<<"="<<i*j<<endl;
  11.       }        
  12.    }     

  13. }
  14. int main()
  15. {
  16.     test(1,9);
  17.     system("pause");
  18.     return 0;
  19. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. void total(int a,int b)
  5. {
  6.     for(int i=1;i<=a;i++)
  7.     {
  8.             for(int j=1;j<=b;j++)
  9.             {
  10.                     cout<<i<<"*"<<j<<"="<<i*j<<"\t";
  11.             }
  12.     }
  13.     cout<<endl;
  14. }
  15. int main()
  16. {
  17.     int a=0,b=0;
  18.     cout<<"請輸入兩個數字"<<endl;
  19.     cin>>a;
  20.     cin>>b;
  21.     total(a,b);
  22.     system("pause");
  23.     return 0;
  24. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. double test(double a,double b)
  5. {
  6.         return a*b;
  7. }
  8. int main()
  9. {
  10.      int a=0,b=0;
  11.      cout<<"請輸入第一個數字"<<endl;
  12.         cin>>a;
  13.    cout<<"請輸入第二個數字"<<endl;
  14.         cin>>b;
  15.        for(int i=1;i<=a;i++)
  16.     {
  17.            for(int j=1;j<=b;j++)
  18.      {
  19.             cout<<i<<"*"<<j<<"="<<test(a,b)<<"\t";        
  20.        }
  21.         }
  22.         system("pause");
  23.         return 0;
  24. }
複製代碼

TOP

返回列表