C语言,多项式相乘

C语言,多项式相乘,第1张

#include <stdioh>

#include <stdlibh>

typedef struct node {

int coefficient, power;

struct node next;

}term;

term new_term(int coefficient, int power) {

term t = (term)malloc(sizeof(term));

t->next = NULL;

t->coefficient = coefficient;

t->power = power;

return t;

}

void free_term(term t) {

free(t);

}

typedef struct list {

term head;

}polynomial;

void init_polynomial(polynomial p) {

p->headnext = NULL;

}

void clear_polynomial(polynomial p) {

term t = p->headnext;

term del;

while (t != NULL) {

del = t;

t = t->next;

free_term(del);

}

p->headnext = NULL;

}

void insert_polynomial(polynomial p, term t) {

t->next = p->headnext;

p->headnext = t;

}

void sort(polynomial p) {

term t;

term next;

int finish = 0, temp;

while (!finish) {

finish = 1;

t = p->headnext;

while (t != NULL) {

next = t->next;

if (next != NULL) {

if (t->power < next->power) {

temp = t->coefficient;

t->coefficient = next->coefficient;

next->coefficient = temp;

temp = t->power;

t->power = next->power;

next->power = temp;

finish = 0;

}

}

t = next;

}

}

}

void combine(polynomial p) {

term t = p->headnext;

term next;

while (t != NULL) {

next = t->next;

if (next != NULL && next->power == t->power) {

t->coefficient += next->coefficient;

t->next = next->next;

free_term(next);

}

else {

t = next;

}

}

}

void multiply(polynomial p1, polynomial p2, polynomial p3) {

term t1 = p1->headnext;

term t2;

clear_polynomial(p3);

init_polynomial(p3);

while (t1 != NULL) {

t2 = p2->headnext;

while (t2 != NULL) {

insert_polynomial(p3, new_term(t1->coefficientt2->coefficient, t1->power + t2->power));

t2 = t2->next;

}

t1 = t1->next;

}

sort(p3);

combine(p3);

}

void input(polynomial p) {

int coef, power;

char c;

init_polynomial(p);

while (true) {

scanf("%d%d", &coef, &power);

insert_polynomial(p, new_term(coef, power));

c = getchar();

if (c == '\n') break;

}

sort(p);

combine(p);

}

void output(polynomial p) {

term t = p->headnext;

while (t != NULL) {

printf("%d %d ", t->coefficient, t->power);

t = t->next;

}

}

int main() {

int i;

polynomial p[3];

for (i = 0; i < 3; i++) {

init_polynomial(&p[i]);

}

for (i = 0; i < 2; i++) {

input(&p[i]);

}

multiply(&p[0], &p[1], &p[2]);

output(&p[2]);

}

请参见下表:设置工具类型端口号码协议Synology Assistant

9999, 9998, 9997UDP备份类型端口号码协议Data Replicator、Data Replicator II 与 Data Replicator III

9999, 9998, 9997, 137, 138, 139, 445TCP网络备份873(Data), 3260(iSCSI LUN)TCP加密的网络备份(远程时间备份)22TCP下载类型端口号码协议eMule4662 (TCP)、4672 (UDP)TCP/UDPBT6890 ~ 6999(用于 v201-30401 之前的固件版本);

16881(用于 DSM v201 及之后的机型)TCP/UDP

网页应用程序类型端口号码协议DSM5000 (>

以上就是关于C语言,多项式相乘全部的内容,包括:C语言,多项式相乘、Synology 服务使用哪些网络端口、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/9669762.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-30
下一篇2023-04-30

发表评论

登录后才能评论

评论列表(0条)

    保存