/*将一个正整数分解质因数如90=2x3x3x5*/ #include<stdio.h> #define L 5 int qualityfun(int intnum); int main(int argc, char *argv[]) { int integer, i, j; i = j = integer = 0; //int quality[L] = {2,3,5,7,11}; int answer[2*L] = {0}; scanf("%d", &integer); printf("%d=", integer); for(i=1;integer!=1;i++) { if(qualityfun(i)==0) continue; while(integer%i==0&&integer!=1) { answer[j++]=i; integer /=i; } } for(i=0;i<j;i++) { if(i>0) putchar(‘x‘); printf("%d", answer[i]); } putchar(‘\n‘); return 0; } int qualityfun(int intnum) { int i, judge; intnum = intnum==1 ? 0 : intnum; for(judge=1,i=2;i<intnum;i++) { if(intnum%i==0) { intnum=judge=0; break; } } if(judge==1) return intnum; else return intnum; }
时间: 2024-10-08 00:00:56