# 用递归求第n项的值 1,2,4,2,3,6,12,6,3,....求第n项值 ## template ```cpp #include int fun(int n, int *x, int *y) { int sum = 0, i; int size = 0; int dd = 1; for (i = 1; i <= (*x); i++) { sum += (2 * i - 1); } if (sum == n) { *y = 2 * (*x) - 1; return (*x); } else if (sum > n) { (*y) = n - (sum - (2 * (*x) - 1)); size = 2 * (*x) - 1; dd = (*x); for (i = 2; i <= (*y); i++) { if (i <= (*x)) dd *= 2; else dd /= 2; } return dd; } else { (*x)++; return fun(n, x, y); } } int main() { int n; int row = 1, col = 0; int val; row = 1; col = 0; printf("请输入n:"); scanf("%d", &n); val = fun(n, &row, &col); printf("第%d项是:%d\n", n, val); return 0; } ``` ## 答案 ```cpp ``` ## 选项 ### A ```cpp ``` ### B ```cpp ``` ### C ```cpp ```