這是我的程式碼
#include<stdio.h>
#include<stdlib.h>
#define MAX 100000
typedef struct element * pointer;
struct element{
int value;
pointer rlink;
};
int main()
{
element *a,*header;
a = (element*)malloc(sizeof(element));
header = a;
int i,num,count[MAX];
while(scanf("%d",&num) != EOF)
{
for(i=0;i<MAX;i++)
count[i] = 0;
a = header;i = 2;
while(i <= num)
{
if(num % i == 0)
{
a->value = i;
count[i]++;
a->rlink = (element*)malloc(sizeof(element));
a = a->rlink;
num /= i;
continue;
}
i++;
}
a->value = -1;
for(a = header;a->value != -1;a = a->rlink)
{
if(a->rlink->value != -1)
{
if(count[a->value] > 1 && a->value != a->rlink->value) printf("%d^%d * ",a->value,count[a->value]);
if(count[a->value] == 1) printf("%d * ",a->value);
}
if(a->rlink->value == -1)
{
if(count[a->value] > 1 && a->value != a->rlink->value) printf("%d^%d\n",a->value,count[a->value]);
if(count[a->value] == 1) printf("%d\n",a->value);
}
}
}
free(a);
return 0;
}
有哪位高手可以幫我找出是哪裡有問題嗎?
謝謝