#include <stdio.h>int isThreeN(int num, int* t); // num为输入的数,t用来返回次方void main(){ int n, t; printf("请输入一个整数:"); scanf("%d", &n); if(isThreeN(n, &t)) printf("%d是3的%d次方\n", n, t); else printf("%d不是3的次方\n", n);} int isThreeN(int num, int* t){ *t = 0; do { num /= 3; (*t)++; } while(num > 3); if(num % 3 == 0 || num == 1) return 1; return 0;}
温馨提示:答案为网友推荐,仅供参考