共回答了20个问题采纳率:75%
#include
#include
#include
#define MAX_NUMBER 500
/*
本程序默认求500以内的亲密数
可以输入参数,求亲密数的范围:
假定程序名为 qinmi.exe
qinmi.exe 300 ==> 即求300以内亲密数
*/
typedef struct _INODE{
int data;
struct _INODE * next;
}INODE;
int TailInsert (INODE * head, int n)
{
INODE * t;
INODE * p;
if (head == NULL)
{
return -1;
}
t = head;
while (t->next != NULL)
{
t = t->next;
}
p = (INODE *) malloc(sizeof(INODE));
if (p == NULL)
{
return -1;
}
t->next = p;
p->data = n;
p->next = NULL;
return 0;
}
INODE * QinMiShu(int n)
{
INODE * head = NULL;
int i;
if (n > 1)
{
head = (INODE *) malloc(sizeof(INODE));
head->data = n;
head->next = NULL;
TailInsert(head, 1);
}
else
{
return NULL;
}
for (i=2; i next;
while(t != NULL){
sum += t->data;
t = t->next;
}
return sum;
}
void FreeMem(INODE * head)
{
INODE * t;
while (head != NULL)
{
t = head;
head = head->next;
free((void *)t);
}
}
int main(int argc, char * argv[])
{
int i, x;
int max = MAX_NUMBER;
INODE * head = NULL;
if (argc > 1)
{
max = atoi(argv[1]);
}
printf("Qingmi number in range: %d: n", max);
for (i=1; i
1年前
2