2014-01-23 37 views
-1

如何寫一個C++程序來打印所有的乘法表,從11到20到每個乘法表的前10個倍數?在線學習C++有哪些好的資源?如何寫一個C++程序來寫乘法表?

+2

可能重複[如何學會正確的C++?(http://stackoverflow.com/questions/2963019/how-to-learn-proper-c) – tumdum

+2

「如何編寫一個C++程序來寫乘法表?「 - 打開文本編輯器並鍵入顯示乘法表的代碼。 – 2014-01-23 08:02:09

+10

可以毫不費力地嘗試作業 –

回答

2
#include <iostream> 
int main(void) { 
    std::cout << "11 12 13 14 15 16 17 18 19 20" << std::endl; 
    std::cout << "22 24 26 28 30 32 34 36 38 40" << std::endl; 
    //... 
    std::cout << "110 120 130 140 150 160 170 180 190 200" << std::endl; 
} 

如果你想與一些特定的結構來做到這一點(如兩個嵌套for -loops循環在區間11:20和1:10),試着問這樣。

+0

是的,我想用for循環來做到這一點。 – user2506435

+0

然後試試。看看http://www.cplusplus.com/doc/tutorial/control/ – urzeit

+0

下次如果有人給你提示應該使用循環,請嘗試搜索互聯網。有* lot *資源。 – urzeit

0

我希望這會幫助你,

int main() { 
    int i, num; 
    num = 11; 
    while(num <= 20){ 
     for(i=1; i<=10; i++){ 
      std::cout<<num*i<<std::endl; 
     } 
     num ++; 
    } 
    return 0; 
} 

讓我知道如果有任何疑問?

+0

'void main()'不是C++。 – 2014-01-23 15:02:07

+0

對不起,我儘管你正在使用Turbo C++。使void main()使用int main和最後返回0; – user3148898

1

像這樣:

#include <iostream> 
#include <iomanip> // setw 

int main() 
{ 
    using namespace std; 
    for(int y = 1; y <= 10; ++y) 
    { 
     cout << setw(3) << y << ": "; 
     for(int x = 11; x <= 20; ++x) 
      cout << setw(4) << x*y; 
     cout << endl; 
    } 
} 
相關問題