#include <stdio.h> //创建单链表 typedef int DateType; typedef struct PList { DateType val; struct PList* next; }ST; //创建节点 ST* CreateBayNode(DateType x) { ST* newnode=(ST*)malloc(sizeof(ST)); //判断开辟空间 if(newnode==NULL) { perror("malloc fail: "); return NULL; } newnode->val=x; newnode->next=NULL; return newnode; } //尾插 void PushBank(ST** head,DateType x) { //创建新节点 ST* newnode=CreateBayNode(x); //判断头是否为NULL if(*head==NULL) { *head=newnode; } else { ST* cur=*head; ST* tail=*head; while(cur) { tail=cur; cur=cur->next; } tail->next=newnode; } } //求和 DateType ListSum(ST* head) { DateType sum=0; ST* cur=head; while(cur) { sum+=cur->val; cur=cur->next; } return sum; } int main() { int n=0; scanf("%d",&n); int arr[n]; for(int i=0;i<n;i++) { scanf("%d",&arr[i]); } ST* SL =NULL; for(int i=0;i<n;i++) { PushBank(&SL,arr[i]); } DateType sum = ListSum(SL); printf("%d\n",sum); return 0; }