我试图对此进行编码,但我无法运行它。请帮我检查我的代码有什么问题。我想要的结果,例子:
The List of Perfect Number
Give me the lastest number(start from 1): 100
6 28
这是一个使用指针的C程序:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i, x, n, *sum;
printf("The List of Perfect Number\n");
printf("Give me the lastest number(start from 1): ");
scanf("%d", &n);
sum = (int *) malloc(sizeof(int));
*sum = 0;
for(x=1;x<=n;x++)
{
for(i=1; i<x; i++)
{
if(x%i == 0)
{
*sum+=i;
}
}
if(*sum == x)
printf("%d", x);
free(sum);
return 0;
}
}