NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <stdio.h>
struct poly{
int coeff;
int expo;
};

struct poly a[10],b[10],c[10];

int readPoly(struct poly []);
int addPoly(struct poly[],struct poly [],int,int,struct poly[]);
void displayPoly(struct poly[], int terms);

int main(){
int t1,t2,t3;

t1=readPoly(a);
printf(" nFirst polynomial:");
displayPoly(a,t1);

t2=readPoly(b);
printf(" nFirst polynomial:");
displayPoly(b,t2);

t3=addPoly(a,b,t1,t2,c);
printf("nn Addition: ");
displayPoly(c,t3);

return 0;
}

int readPoly(struct poly p[10]){
int t1,i;
printf("nn Enter the total number of terms in the polynomial:");
scanf("%d",&t1);
printf("n Enter the COEFFICIENT and EXPONENT in DESCENDING ORDERn");
for(i=0;i<t1;i++){
printf(" Enter the Coefficient(%d): ",i+1);
scanf("%d",&p[i].coeff);
printf(" Enter the Exponent(%d): ",i+1);
scanf("%d",&p[i].expo);
}
return(t1);
}

int addPoly(struct poly p1[10],struct poly p2[10],int t1,int t2,struct poly p3[10]){
int i=0,j=0,k=0;
while(i<t1 && j<t2){
if(p1[i].expo == p2[j].expo){
p3[k].coeff=p1[i].coeff + p2[j].coeff;
i++;j++;k++;
}
else if(p1[i].expo > p2[j].expo){
p3[k].coeff=p1[i].coeff;
p3[k].expo=p1[i].expo;
i++;k++;
}
else{
p3[k].coeff=p2[j].coeff;
p3[k].expo=p2[j].expo;
j++;k++;
}
}
while(i<t1){
p3[k].coeff=p1[i].coeff;
p3[k].expo=p1[i].expo;
i++;k++;
}
while(j<t2){
p3[k].coeff=p2[j].coeff;
p3[k].expo=p2[j].expo;
j++;k++;
}
return(k);
}

void displayPoly(struct poly p[10],int term){
int k;
for(k=0;k<term-1;k++)
printf("%d(x^%d)+",p[k].coeff,p[k].expo);
printf("%d(x^%d)+",p[term-1].coeff,p[term-1].expo);
}
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.