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));
return0; }
intFactorialSum(List L) { int i, Num; int Sum = 0; while (L != NULL) //遍历整个链表 { Num = 1; for (i = 1; i <= L->Data; i++)//从每个节点读取数据计 { Num = Num*i; //算每个节点数据的阶乘 } Sum = Sum + Num; //对节点数据求和 L = L->Next; } return Sum; //返回单链表结点的阶乘和 }