bin554385863 发表于 2019-8-4 20:26:42

C++乘法表

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

int main(int argc, char const *argv[])
{
    for (size_t i = 1; i < 10; i++)
    {
      for (size_t j = 1; j <= i; j++)
      {
            printf("%d X %d = %2d ", j, i, i*j);
      }
      cout << endl;
    }

    return 0;
}
-------------------------------------------------------------
Microsoft Windows [版本 10.0.16299.1087]
(c) 2017 Microsoft Corporation。保留所有权利。

E:\Users\86184\Documents\Code>cmd /C "c:\Users\86184\.vscode\extensions\ms-vscode.cpptools-0.24.1\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-2ymfammo.to1 --stdout=Microsoft-MIEngine-Out-ceztgzut.gji --stderr=Microsoft-MIEngine-Error-qykawhzi.32u --pid=Microsoft-MIEngine-Pid-13j2w13j.kck "--dbgExe=E:\My Program\MinGW\bin\gdb.exe" --interpreter=mi "
1 X 1 =1
1 X 2 =2 2 X 2 =4
1 X 3 =3 2 X 3 =6 3 X 3 =9
1 X 4 =4 2 X 4 =8 3 X 4 = 12 4 X 4 = 16
1 X 5 =5 2 X 5 = 10 3 X 5 = 15 4 X 5 = 20 5 X 5 = 25
1 X 6 =6 2 X 6 = 12 3 X 6 = 18 4 X 6 = 24 5 X 6 = 30 6 X 6 = 36
1 X 7 =7 2 X 7 = 14 3 X 7 = 21 4 X 7 = 28 5 X 7 = 35 6 X 7 = 42 7 X 7 = 49
1 X 8 =8 2 X 8 = 16 3 X 8 = 24 4 X 8 = 32 5 X 8 = 40 6 X 8 = 48 7 X 8 = 56 8 X 8 = 64
1 X 9 =9 2 X 9 = 18 3 X 9 = 27 4 X 9 = 36 5 X 9 = 45 6 X 9 = 54 7 X 9 = 63 8 X 9 = 72 9 X 9 = 81

E:\Users\86184\Documents\Code>
===============================================
printf("%d X %d = %2d ", j, i, i*j);
怎么用cout替代?{:5_104:}

Neverturnback 发表于 2019-8-4 21:16:41

本帖最后由 Neverturnback 于 2019-8-4 21:21 编辑

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

int main(int argc, char const *argv[])
{
        for (size_t i = 1; i < 10; i++)
        {
                for (size_t j = 1; j <= i; j++)
                {
                        //printf("%d X %d = %2d ", j, i, i*j);
                        cout << j <<" X "<< i <<" = "<< i * j<<"";//count会自动读取数据类型,所以直接用就行了,很方便,每个变量用<<分开
                }
                cout << endl;//endl是换行和printf里面的\n相似
        }


        getchar();
        return 0;
}

micolar 发表于 2019-8-4 21:26:58

楼主你程序运行没问题啊

bin554385863 发表于 2019-8-4 21:51:16

micolar 发表于 2019-8-4 21:26
楼主你程序运行没问题啊

没啊,正常运行啊.C++可以兼容C语言的
页: [1]
查看完整版本: C++乘法表