老六解题法 #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 人评分
Tom数 (C++代码)浏览:843 |
【亲和数】 (C语言代码)浏览:559 |
简单的a+b (C语言代码)浏览:712 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:1422 |
A+B for Input-Output Practice (III) (C语言代码)浏览:578 |
WU-整除问题 (C++代码)浏览:616 |
C语言程序设计教程(第三版)课后习题6.8 (C++代码)浏览:597 |
【计算两点间的距离】 (C语言代码)浏览:1502 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:693 |
字符逆序 (C语言代码)浏览:473 |