C++写一个简单的“九九乘法表”用来练手;
步骤一:创建main.cpp文件
touch main.cpp
步骤二:在main.cpp文件中写入如下代码
#include <iostream>
using namespace std;
int main(int argc, char **argv){
int i,j;
for(i = 1; i <= 9; i++){
for(j = 1; j<=i; j++){
cout << j << "*" << i << "=" << j*i << " ";
}
cout << endl;
}
}
步骤三:编写CMakeLists.txt文件。(一般我都是去直接copy一个过来修改)
# cmake needs this line
cmake_minimum_required(VERSION 2.8)
# Define project name
project(nineninecode_project)
# Declare the executable target built from your sources
add_executable(nineninecode main.cpp)
步骤四:创建build文件夹,编译
mkdir build
cd build
cmake ..
make
运行
./nineninecode
结果截图