本题要求实现一个函数,求单链表L结点的阶乘和。这里默认所有结点的值非负,且题目保证结果在int范围内。 函数接口定义: ```c int FactorialSum( List L ); ``` 其中单链表List的定义如下: ```c typedef struct Node *PtrToNode; struct Node { int Data; /* 存储结点数据 */ PtrToNode Next; /* 指向下一个结点的指针 */ }; typedef PtrToNode List; /* 定义单链表类型 */ ``` 裁判测试程序样例: ```c #include #include typedef struct Node *PtrToNode; struct Node { int Data; /* 存储结点数据 */ PtrToNode Next; /* 指向下一个结点的指针 */ }; typedef PtrToNode List; /* 定义单链表类型 */ int FactorialSum( List L ); int main() { int N, i; List L, p; scanf("%d", &N); L = NULL; for ( i=0; iData); p->Next = L; L = p; } printf("%d\n", FactorialSum(L)); return 0; } /* 你的代码将被嵌在这里 */ ``` 输入样例: 3 5 3 6 输出样例: 846 ------------ **答案** ```c int FactorialSum( List L ){ int sum=0,i; List p=L; while(p){ int ji=1; for(i=1;i<=p->Data;i++){ ji*=i; } sum+=ji; p=p->Next; } return sum; } ``` Last modification:March 18th, 2020 at 10:04 am © The copyright belongs to the author Support If you think my article is useful to you, please feel free to appreciate ×Close Appreciate the author 谢谢,不用了 Pay by AliPay Pay by WeChat
可以
OωO