1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
emmasim [6.3K]
3 years ago
13

Write a function input_poly(ptr1) that reads in two polynomials at a time with coefficient and exponent from a file cp7_in.txt.

The file will contain 2n polynomials, where n is an integer that is 10 or less. Space for the polynomial will be allocated in run time and there is no limit to the size of the polynomial, e..g the first two lines of the file is
Computers and Technology
1 answer:
Tanya [424]3 years ago
6 0

Answer:

try this

Explanation:

#include<stdio.h>

#include<malloc.h>

typedef struct poly{ double coff;

int pow;

struct poly *link; }SL;

void create(SL **head)

{

*head=NULL;

}

//Insertion  

void ins_beg(SL ** head, double c, int pw)

{

SL *ptr;

ptr=(SL *)malloc(sizeof(SL));

ptr->coff=c;

ptr->pow=pw;

ptr->link=*head;

*head=ptr;

}

void trav(SL **head)

{

SL *ptr;

ptr=*head;

printf("\n\t Cofficient Exponent\n");

while(ptr!=NULL)

{ printf("\t\t%3.2f \t%d\n",ptr->coff, ptr->pow);

ptr=ptr->link;

}

}

//addition of polynomial............

void mult(SL *pl1, SL *pl2, SL **res)

{

SL trav1, trav2, ptr, new1,*loc;

int x,y;

trav1=*pl1;

while(trav1!=NULL)

{

trav2=*pl2;

while(trav2!=NULL)

{

x=(trav1->coff)*(trav2->coff);

y=(trav1->pow)+(trav2->pow);

//printf("\t%d\t%d\n",x,y);

if(*res==NULL)

{

new1=(SL *)malloc(sizeof(SL));

new1->coff=x;

new1->pow=y;

new1->link=NULL;

*res=new1;

}

else

{

ptr=*res;

while((y<ptr->pow)&&(ptr->link!=NULL))

{

loc=ptr;

ptr=ptr->link;

}

if(y==ptr->pow)

ptr->coff=ptr->coff+x;

else

{

if(ptr->link!=NULL)

{

new1=(SL *)malloc(sizeof(SL));

new1->coff=x;

new1->pow=y;

loc->link=new1;

new1->link=ptr;

}

else

{

new1=(SL *)malloc(sizeof(SL));

new1->coff=x;

new1->pow=y;

ptr->link=new1;

new1->link=NULL;

}

}

}

trav2=trav2->link;

}

trav1=trav1->link;

}

}

//...addition..............

void add(SL *pl1, SL *pl2)

{

SL trav1, ptr, *new1,*loc; trav1=*pl1;

while(trav1!=NULL)

{

loc=ptr=*pl2;

while((trav1->pow<ptr->pow)&&(ptr->link!=NULL))

{

loc=ptr; ptr=ptr->link;

}

if(loc==ptr)

{

new1=(SL *)malloc(sizeof(SL));

new1->coff=trav1->coff;

new1->pow=trav1->pow;

new1->link=*pl2;

*pl2=new1;

}

else

if(trav1->pow==ptr->pow)

{

ptr->coff=ptr->coff+trav1->coff;

//ptr->pow=ptr->pow+trav1->pow;

}

else

if(ptr->link!=NULL)

{

new1=(SL *)malloc(sizeof(SL));

new1->coff=trav1->coff;

new1->pow=trav1->pow;

new1->link=ptr;

loc->link=new1;

}

else

{

new1=(SL *)malloc(sizeof(SL));

new1->coff=trav1->coff;

new1->pow=trav1->pow;

new1->link=NULL;

ptr->link=new1;

}

trav1=trav1->link;

}

}

int main()

{

SL first, sec, *res;

create(&first);

ins_beg(&first,10.25,0);

ins_beg(&first,4,1);

ins_beg(&first,5,2);

ins_beg(&first,4,4);

printf("\nFirst Polinomial:\n");

trav(&first);

create(&sec);

ins_beg(&sec,11,0);

ins_beg(&sec,6,1);

ins_beg(&sec,4,2);

ins_beg(&sec,3,3);

printf("\nSecond Polinomial:\n");

trav(&sec);

create(&res);

printf("\nMultiplication of two Polinomial:\n");

mult(&first,&sec,&res);

trav(&res);

printf("\nAddition of two Polinomial:\n");

add(&first,&sec);

trav(&sec);

//trav(&first);

return 0;

}

You might be interested in
Write the definition of a class clock. the class has no constructors and three instance variables. one is of type int called hou
expeople1 [14]
<span>The definition of a class clock. the class has no constructors and three instance variables. one is of type int called hours, initialized to 12, another is of type boolean called isticking, and the last one is of type integer called diff. 
</span><span>
public class Clock

{private int hours = 12;
private boolean isTicking;
private Integer diff;}</span>
4 0
2 years ago
The second row of letters on the keyboard is called the______ row
Mkey [24]
The 2nd row of ur keyboard its called home row !

5 0
3 years ago
Read 2 more answers
I live in Pennsylvania which observes eastern standard time.
goldfiish [28.3K]

Answer:

mudar o horário de acordo com a vista

Explanation:

4 0
2 years ago
If a website ends with .gov does it mean that its written by the government or?
Soloha48 [4]
Umm... No. (I'm pretty sure)
7 0
3 years ago
Read 2 more answers
What command in cisco IOS allows the user to see the routing table
maksim [4K]

Answer:

Show IP route command

Explanation:

7 0
2 years ago
Other questions:
  • How many total channels are available in the United States for wireless LAN use in the unlicensed 2.4ghz ism band ?
    6·1 answer
  • A(n) ____________________ is a set of programs that coordinates all the activities among computer or mobile device hardware.
    10·1 answer
  • Research information technology affects on job market, career pathways, occupational outlooks in business and finance and synthe
    7·1 answer
  • Select the statements that are true regarding the future of technology. Select 2 options.
    12·1 answer
  • If data from a DOS system is electronically sent to an EHR or other Windows-based system via an interface to populate an indexed
    7·1 answer
  • Suppose that a computer can read or write a memory word in 5 nsec. Also suppose that when an interrupt occurs, all 32 CPU regist
    10·2 answers
  • How I to turn this ''loop while'' in ''loop for''? var i = 0; while (i &lt; 20) { var lineY = 20 + (i * 20); line(0, lineY, 400,
    11·1 answer
  • What can you find the under the privacy policy section of a shopping website?
    12·1 answer
  • How scientist and technology beliefs society
    14·1 answer
  • Discuss five domains of Instructional technology​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!