老六解题法 #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语言代码)浏览:555 |
蓝桥杯历届试题-九宫重排 (C++代码)浏览:2783 |
C语言训练-计算:t=1-1/(2*2)-1/(3*3)-...-1/(m*m) (C语言代码)浏览:785 |
简单的a+b (C语言代码)浏览:530 |
简单的a+b (C语言代码)浏览:340 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:1245 |
C语言训练-求1+2!+3!+...+N!的和 (C语言代码)浏览:790 |
C语言程序设计教程(第三版)课后习题8.2 (C语言代码)浏览:5232 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:542 |
字符逆序 (C语言代码)浏览:460 |