老六解题法 #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 人评分
【绝对值排序】 (C语言代码)浏览:484 |
十->二进制转换 (C语言代码)浏览:1417 |
点我有惊喜!你懂得!浏览:1352 |
永远的丰碑 (C语言代码)浏览:662 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:557 |
C语言训练-立方和不等式 (C语言代码)浏览:763 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:904 |
妹子杀手的故事 (C语言代码)浏览:1244 |
简单的a+b (C语言代码)浏览:844 |
1124题解浏览:598 |