Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize polynomial addition in C language

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how C language realizes polynomial addition". In daily operation, I believe that many people have doubts about how C language realizes polynomial addition. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt of "how C language realizes polynomial addition"! Next, please follow the editor to study!

The specific code is as follows:

/ / addition and multiplication of polynomials # include#include#pragma warning (disable:4996) / / compatible scanftypedef struct node {int coef; int expon; struct node* link;} Polynode,*Polynomial;Polynomial InsertPolyLinklist (Polynomial in,Polynomial Pread) {Pread- > link = in; Pread = in; in- > link = NULL; return Pread;} Polynomial ReadPoly (void) {Polynomial Pread = (Polynomial) malloc (sizeof (Polynode)); Pread- > link = NULL; Polynomial H = Pread; int N Scanf ("% d", & N); while (N muri -) {Polynomial p = (Polynomial) malloc (sizeof (Polynode)); scanf ("% d% d", & p-> coef, & p-> expon); Pread= InsertPolyLinklist (pForce Pread);} Polynomial F; F = H-> link; free (H); return F } void PrintPoly (Polynomial F) {while (F! = NULL) {printf ("% d% d", F-> coef, F-> expon); F = F-> link;} printf ("\ n");} Polynomial Add (Polynomial p1, Polynomial p2) {Polynomial T1 printf T2; Polynomial p = (Polynomial) malloc (sizeof (Polynode)); p-> link = NULL; Polynomial q = p; Polynomial read While (t1&&t2) {if (T1-> expon = = T2-> expon) {if (T1-> coef + T2-> coef) {T1-> coef = T1-> coef + T2-> coef; T1-> expon = T1-> expon; read = T1; Q-> link = read; Q = read; T1 = T1-> link; T2 = T2-> link }} else {if (T1-> expon > T2-> expon) {read = T1; Q-> link = read; Q = read; T1 = T1-> link;} else {if (T1-> expon)

< t2->

Expon) {read = T2; Q-> link = read; Q = read; T2 = T2-> link;} if (T1) {Q-> link = T1;} if (T2) {Q-> link = T2;} Polynomial F = p-> link; free (p); return F;} int main (void) {Polynomial p1, p2, pp, ps P1 = ReadPoly (); PrintPoly (p1); p2 = ReadPoly (); PrintPoly (p2); pp = Add (p1, p2); PrintPoly (pp); / / ps = Mult (p1, p2); / / PrintPoly (ps); return 0;} at this point, the study of "how C language realizes polynomial addition" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report