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
Viet drives around and checks meters to document the amount of electricity used in homes. What Energy pathway is he a part of? E
Svet_ta [14]
As Viet drives around and checks meters to document the amount of electricity used in homes he would be part of the energy distribution process since the electricity is distributed off  a power line into the house and then within the house by the wiring to the lights and the electrical outlets for usage by the inhabitants.
7 0
3 years ago
Read 2 more answers
Vitamins and minerals dissolve easily in water.True or false?
noname [10]
True vitamins and minerals dissolves in water
8 0
3 years ago
How is the Microsoft Word 2013 window organized?
Alenkasestr [34]
The answer is (A): with contextual tabs for major groupings of editing features and ribbons with specific groupings to organize commands.


Contextual tab or tabs are hidden menu that appears when objects like images or texts are selected in programs like MS Word 2013. They typically contain one or more commands applicable to a selected text or object only. They are there in the Ribbon when you need them and disappear when you do not need them anymore. They are basically used for major groupings of editing features.
A ribbon on the other hand help users understand how commands are used directly and efficiently. It organizes a program’s features into a series of tabs.




6 0
3 years ago
Read 2 more answers
Some of the more important __________ include anti-virus (and anti-malware), host-based firewall, system hardening (removing unw
xeze [42]

Answer:

host-based security measures

Explanation:

Anti-virus, host-based firewall, system hardening, change control, and log management are host based.

6 0
3 years ago
Which button could Pamela press in the Microsoft Word spell checker to make the word “colour” instantly change to “color” whenev
Savatey [412]
One step is to right click on the word to add it to her personal dictionary. or, <span><span>Press F7. Word starts the spelling and grammar checking utility. </span><span>Make corrections, as appropriate, when prompted.
</span></span>

However, one can create a macro that would do the conversions :

1) Identify a list of words whose spelling you want to convert.2) Turn on the macro recorder. 3) Use the Replace feature to replace the spellings.4) Turn off the macro recorder.

The macro will do a conversion from one to the other. Later, as we have more words that need to be automatically replaced, we can just edit the macro and add those words.

8 0
3 years ago
Other questions:
  • Torque is defined as _____.
    7·1 answer
  • What is one example of technology influencing health​
    9·1 answer
  • What is the automotive name for the large wires that allow more electrical current to flow ?
    12·1 answer
  • For security reasons a network administrator needs to ensure that local computers cannot ping each other. which settings can acc
    5·1 answer
  • The radix sort
    14·1 answer
  • The invention of the transistor was important to the development of computers because
    14·1 answer
  • Which of these would NOT be a valid Internet Control Message Protocol (ICMP) error message:
    6·1 answer
  • When an external device becomes ready to be serviced by the processor the device sends a(n)_________ signal to the processor.
    8·1 answer
  • Why does the peot use a simular pharase at the beggining of each stanza
    8·1 answer
  • Which of the following statements about recommendation engines is TRUE?A: An online recommendation engine is a set of algorithms
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!