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
A startup company is using an excel spreadsheet to keep track of the billable hours that each employee spends on a project. As y
s2008m [1.1K]

Answer:

Hello there! There are 4 parts to this question, all regarding relational database concepts.

Explanation:

Parts 1, 2, 3, 4 are drawn in attachments. For Part 4, the "foreign keys" would be the id fields of the joining table, and the "primary keys" are the IDs of the table itself. Data types are "integer" for ID, "string" for text columns like Name and Location, and "Decimal" for Hourly rate in the Timesheet table. Note that we can further simplify the erd from the one constructed earlier in part 3 to remove the Project Manager model and instead add a Project Manager "boolean" flag in the Employee table since a Project Manager is also an Employee.  

6 0
3 years ago
:) :) :):):):)):):):)):)/):))::)):):):):):)):):)):):))/):):))
pashok25 [27]

Answer:

:)))))))))))))))))))))))))))))))))))))))) thanks

3 0
3 years ago
What is the significance of both RAID and IP technologies as precursors to the SAN environment?
Dominik [7]

Explanation:SAN(Storage area network) technology is the network technology that is used for the accessing of the block level network towards the storage units. It is made up of the storage components, switches etc.

RAID(Redundant Array of Independent Disks) and IP(internet protocol) is used as the precursor because they work better than the SAN. They have the ability to solve the issue that occur in the SAN technology like complexity,and other faulty issues.They maintain the fault tolerance quality and maintaining the network.

3 0
4 years ago
In most languages, if a file does not exist and a program attempts to open it in append mode, what happens?
chubhunter [2.5K]

Answer:

It create a new file in which writing of data begins.

Explanation:

A file can be open in the three mode:

-r (Read mode): open an existing file for the purpose of reading data from it.

-w (write mode): Create a new file for the purpose of writing data to it.

-a (append mode): open an existing file for the purpose of appending extra data to it but if the file does not exist, it create a new file and start writing data to it.

5 0
4 years ago
1. Which of these is NOT true about Torsion Bars? A. They can be used to adjust Ride Height B. They can be adjusted anytime sinc
Strike441 [17]

My answer is B: They can be adjusted anytime since they don't affect alignment angles.

Option A is correct. Manufactures can change the Torsion bar to adjust the ride height. This is done to compensate the engine weight. Option C is  correct. The torsion’s bar acquires a twisting motion on one end of the suspension, and is firmly fixed to the car’s frame at the other end. Actually, it attaches to the lower control ARM and a cross member key on the chassis frame. Option D is also correct. When a wheel passes over a bump, the Torsion bar acquires a twisting motion on one end of an object whose other end is fixed.


7 0
3 years ago
Other questions:
  • #1. List examples of where it matters whether items are in order (sorted).
    10·1 answer
  • A(n _______________ is a pre-written formula that is built into excel
    12·1 answer
  • Key physical database design decisions typically do not include: A) choosing the storage format for each attribute from the logi
    12·1 answer
  • Shawn thought that the screen of the block-based program he was using was
    15·1 answer
  • a machine needs a minimum of 100 sec to sort 1000 names by quicksort what is the approximate worst case time needed to sort 100
    13·1 answer
  • Encapsulation is a form of information hiding and an important characteristic of object-oriented programming. When a programmer
    6·1 answer
  • Puter Science (IS)
    14·1 answer
  • Dgvdsgf cvdzgb fgvsdxchygfdrzvdszfgvsdzxd
    9·1 answer
  • Which of these is an example of input?
    6·1 answer
  • ASAP PLEASE the online research you did to describe how Senet is related to the culture and historical period when it was create
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!