#include <stdio.h>
#include <stdlib.h>
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; i<N; i++ ) {
p = (List)malloc(sizeof(struct Node));
scanf("%d", &p->Data);
p->Next = L; L = p;
}
printf("%d\n", FactorialSum(L));
return 0;
}
/* 你的代码将被嵌在这里 */
int fun(int n)
{
if(n==0||n==1)
return 1;
else
{
return n*fun(n-1);
}
}
int FactorialSum( List L )
{
int sum=0;
while(L!=NULL)
{
int t=fun(L->Data);
sum+=t;
L=L->Next;
}
return sum;
}
6-5 求单链表结点的阶乘和 (15分)
猜你喜欢
转载自blog.csdn.net/qq_38054511/article/details/104107970
今日推荐
周排行