NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#include<process.h>
#include<math.h>
struct node
{
float cf;
int px,py,pz;
int flag;
struct node *link;
};
typedef struct node *NODE;

NODE getnode()
{
NODE x;
x=(NODE) malloc (sizeof(struct node));
if(x==NULL)
{
printf("out of memoryn");
exit(0);
}
return x;
}

NODE insert_rear(float cf,float x , float y, float z,NODE head)
{
NODE temp,cur;
temp=getnode();
temp->cf=cf;
temp->px=x;
temp->py=y;
temp->pz=z;
temp->flag=0;
cur=head->link;
while(cur->link!=head)
{
cur=cur->link;
}
cur->link=temp;
temp->link=head;
return head;
}


void display(NODE head)
{
NODE temp;
if(head->link==head)
{
printf("polynominal doesn't exsitsn");
return;
}
temp=head->link;
while(temp!=head)
{
printf("+ % 5.2fx^%dy^%dz^%d",temp->cf,temp->px,temp->py,temp->pz);
temp=temp->link;
}
printf("n");
}
NODE add_poly(NODE h1,NODE h2, NODE h3)
{
NODE p1,p2;
int x1,x2,y1,y2,z1,z2,cf1,cf2,cf;
p1=h1->link;
while(p1!=h1)
{
x1=p1->px;
y1=p1->py;
z1=p1->pz;
cf1=p1->cf;
p2=h2->link;
while(p2!=h2)
{
x2=p2->px;
y2=p2->py;
z2=p2->pz;
cf2=p2->cf;
if(x1==x2 && y1==y2 && z1==z2) break;
p2=p2->link;
}
if(p2!=h2)
{
cf=cf1+cf2;
p2->flag=1;
if(cf!=0)
h3=insert_rear(cf,x1,y1,z1,h3);
}
else
h3=insert_rear(cf1,x1,y1,z1,h3);
p1=p1->link;
}

p2=h2->link;
while(p2!=h2)
{
if(p2->flag==0)
{
h3=insert_rear(p2->cf,p2->px,p2->py,p2->pz,h3);
}
p2=p2->link;
}
return h3;
}

NODE read_poly(NODE head)
{
int i;
int px,py,pz;
float cf;
printf("enter the coeffecient as -999 to end the polynominaln");
for(i=1;;i++)
{
printf("enter the %d termn",i);
printf("coeff=");
scanf("%f",&cf);
if(cf==-999) break;
printf("pow x=");
scanf("%d",&px);
printf("pow y=");
scanf("%d",&py);
printf("pow z=");
scanf("%d",&pz);

head=insert_rear(cf,px,py,pz,head);
}
return head;
}


void polysum()
{
NODE h1,h2,h3;
h1=getnode();
h2=getnode();
h3=getnode();
h1->link=h1;
h2->link=h2;
h3->link=h3;
printf("enter the first polynominaln");
h1=read_poly(h1);
printf("enter the second polynominaln");
h2=read_poly(h2);
h3=add_poly(h1,h2,h3);
printf(" the first polynominal isn");
display(h1);
printf("second polynominal isn");
display(h2);
printf("the sum of two polynominal isn");
display(h3);
}
void represent_evaluate()
{
NODE e1,temp;
int x,y,z;
float sum=0.0;
e1=getnode();
e1->link=e1;
printf("enter the polynominaln");
e1=read_poly(e1);
printf("polynominal i s n");
display(e1);
printf("enter the values of coefficientn");
scanf("%d%d%d",&x,&y,&z);
if(e1==NULL)
{
printf("list is empty");

}
else
{
temp=e1->link;
while(temp!=e1)
{

sum+=temp->cf*pow(x,temp->px)*pow(y,temp->py)*pow(z,temp->pz);
temp=temp->link;
}
// sum+=temp->cf*pow(x,temp->px)*pow(y,temp->py)*pow(z,temp->pz);
printf("the total sum is %fn",sum);
}
return;
}
void main()
{
int choice;
clrscr();
while(1)
{
printf("nnnt1.represent and evaluate...t2.ADD TWO poly..t3.Exit...");
printf("nnntEnter Your Choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: represent_evaluate();break;
case 2:polysum();break;
case 3:exit(0);
default: printf("nnntEnter proper Choice....");
}
}

}

     
 
what is notes.io
 

Notes.io is a web-based application for 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 12 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.