2014-01-23 35 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; 
    } 
} 
相关问题