例
#include <bits/stdc++.h> using namespace std; //计算周期数 int totalCycle(int vertices) { int result = 0; result = pow(vertices, 2) - (3 * vertices) + 3; return result; } //计算边数 int Edges(int vertices) { int result = 0; result = 2 * (vertices - 1); return result; } //计算直径 int Diameter(int vertices) { int result = 0; if (vertices == 4) result = 1; else result = 2; return result; } int main() { int vertices = 4; cout << "Number of Cycle = " << totalCycle(vertices) << endl; cout << "Number of Edges = " << Edges(vertices) << endl; cout << "Diameter = " << Diameter(vertices); return 0; }
输出结果
Number of Cycle = 7 Number of Edges = 6 Diameter = 1