在本教程中,我们将讨论查找星号的程序。
为此,我们将获得一个随机数。我们的任务是找到以下公式给定的特定位置的星号-
6n(n-1)+ 1
#include <bits/stdc++.h>
using namespace std;
//在第n个位置返回星号
int findStarNum(int n) {
return (6 * n * (n - 1) + 1);
}
int main() {
int n = 3;
cout << findStarNum(n);
return 0;
}输出结果
37