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
Can someone tell me what this means Higfaa
Arisa [49]

Answer:

it's a Jamaican slang

Explanation:

it depends on the wah it is used

7 0
2 years ago
What Is an Antivirus?
wariber [46]
Antivirus software, or anti-virus software, also known as anti-malware, is a computer program used to prevent, detect, and remove malware. Antivirus software was originally developed to detect and remove computer viruses, hence the name.
8 0
3 years ago
Read 2 more answers
A keyboard shortcut is a key or combination of keys that you press to access a feature or perform a command. ___________________
andrey2020 [161]
I believe that this is true.
Ctrl+F
Ctrl+C
Ctrl+V
These are all keyboard shortcuts.

8 0
3 years ago
How do I find a space in my String and replace it? JAVA
Fantom [35]

Answer:

This article shows how to use regex to remove spaces in between a String.

A string with spaces in between.

String text = "Hello World Java.";

We want to remove the spaces and display it as below:

Hello World Java.

1. Java regex remove spaces

In Java, we can use regex \\s+ to match whitespace characters, and replaceAll("\\s+", " ") to replace them with a single space.

Regex explanation.

`\\s` # Matches whitespace characters.

+ # One or more

StringRemoveSpaces.java

package com.mkyong.regex.string;

public class StringRemoveSpaces {

public static void main(String[] args) {

String text = "Hello World Java.";

String result = text.replaceAll("\\s+", " ");

System.out.println(result);

}

}

Output

Terminal

Hello World Java.

8 0
3 years ago
HIPAA protects which of the following kinds of data?
Gelneren [198K]
The answer is a i looked up the question and it says a
5 0
3 years ago
Read 2 more answers
Other questions:
  • How does the team know what to work upon during the iteration
    6·1 answer
  • Alexei was given a key to a substitution cipher. The key showed that the entire alphabet was rotated 13 steps. What type of ciph
    7·1 answer
  • NEED HELP PLEASE-
    7·2 answers
  • Which of the following is NOT an advantage to using inheritance?
    13·1 answer
  • 1. Which of the following statements are true about routers and routing on the Internet. Choose two answers. A. Protocols ensure
    9·2 answers
  • What is the name of the function used to open a file in C?
    8·1 answer
  • Given an char variable last that has been initialized to a lowercase letter, write a loop that displays all possible combination
    8·1 answer
  • Well the last week has been kind of terrible...
    9·2 answers
  • A thesaurus is an example of a(n)
    5·2 answers
  • Select the correct text in the passage.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!