看似不难?
提示: 作者被禁止或删除 内容自动屏蔽
#include <stdio.h> #include <stdlib.h> #define MAX 50 #define SAVE_FAC(fact, exp) { if (exp > 0) \ fac[count] = fact, \ exps[count++] = i; \ } int main() { int fac[MAX],exps[MAX]; int n, work,count = 0,i, k; printf("Input a positive integer:"); scanf("%d",&n); for (i=0,work=n; (work & 0x01UL)==0 && work>1; work>>=1,i++); SAVE_FAC(2, i); for (k = 3; k <= work; k += 2) { for (i = 0; work % k == 0 && work > 1; work /= k, i++); SAVE_FAC(k, i); } printf("%d=1", n); for (i = 0; i < count; i++) { while(exps[i]--) printf("*%d", fac[i]); } return 0; }