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]
2 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]2 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
When you are ready to print your document, what tab and command should you choose from the menu?
Margaret [11]

Answer:

File, Print UWU

Explanation:

3 0
3 years ago
Read 2 more answers
Meaning of 'WSAD" iiiiii
Anit [1.1K]

Answer:

Websphere Studio Application Developer

7 0
3 years ago
Read 2 more answers
Explain the unique reason why assember language is perfered to high level language
Zigmanuir [339]

The unique reason why assembler language is preferred to high level language is that  It is said to be memory efficient and it is one that requires less memory.

<h3>Why is assembly language better than other kinds of high level?</h3>

It implies means that the programs that one uses to write via the use of high-level languages can be run easily on any processor that is known to be independent of its type.

Note that it is one that has a lot of  better accuracy and an assembly language is one that carries out a lot of better functions than any high-level language, in all.

Note also that the advantages of assembly language over high-level language is in terms of its Performance and accuracy as it is better than high-level language.

Hence, The unique reason why assembler language is preferred to high level language is that  It is said to be memory efficient and it is one that requires less memory.

Learn more about assembler language from

brainly.com/question/13171889

#SPJ1

3 0
1 year ago
How can templates be made available to other users?
Daniel [21]

Answer:

b

Explanation:

4 0
3 years ago
A poker hand consists of 5 cards drawn at random without replacement from a 52 card deck. Using python and the cards data frame
PSYCHO15rus [73]

Answer:

# Python program to shuffle a deck of card

# importing modules

import itertools, random

# make a deck of cards

deck = list(itertools.product(range(1,14),['Spade','Heart','Diamond','Club']))

# shuffle the cards

random.shuffle(deck)

# draw five cards

print("You got:")

for i in range(5):

  print(deck[i][0], "of", deck[i][1])

Output

You got:

5 of Heart

1 of Heart

8 of Spade

12 of Spade

4 of Spade

Explanation:

5 0
3 years ago
Other questions:
  • Which statement describes the word "iterative"?
    7·2 answers
  • What's the fastest way to reset Android pin?​
    5·1 answer
  • Why is it important to have regular maintenance and care of your office equipment?
    5·1 answer
  • The point at coordinates (2, -18) is in what direction from the origin?
    7·1 answer
  • Given the strings s1 and s2 that are of the same length, create a new string consisting of the last character of s1 followed by
    10·1 answer
  • When using a file name you have to use only lower case letters<br>true or false
    11·1 answer
  • When was internet started in which year​
    13·2 answers
  • Please help!
    10·2 answers
  • Please answer me fast ​
    6·2 answers
  • Write IF() function for student 3, If total mark is greater than 10 then print
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!