老六解题法 #include<stdio.h> int main(){ int a[10],b[10]; int sum1 = 0,sum2 = 0; for(int i=0;i<10;i++){ scanf("%d%d",&a[i],&b[i]); sum1+=a[i]; sum2+=b[i]; } printf("%d+%di",sum1,sum2); } 正规解题法 #include<stdio.h> #include<stdlib.h> typedef struct elemtype { int a; int b; struct elemtype *next; } elemtype; void xf(elemtype *L) { elemtype *ch = (elemtype *)malloc(sizeof(elemtype)); scanf("%d%d", &ch->a, &ch->b); ch->next = NULL; while (L->next != NULL) { L = L->next; } L->next = ch; } void xf1(elemtype *L) { int a = 0, b = 0; elemtype *ch = L->next; while (ch != NULL) { a += ch->a; b += ch->b; ch = ch->next; } printf("%d+%di", a, b); } int main() { elemtype *L; L = (elemtype *)malloc(sizeof(elemtype)); L->next = NULL; for (int i = 0; i < 10; i++) { xf(L); } xf1(L); elemtype *tem; while(L!=NULL){ tem = L; L=L->next; free(tem); } return 0; }
个人推荐老六解法,哈哈哈哈
0.0分
0 人评分