Saturday 13 December 2014

wap for polynomial

wap for polynomial

#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#include<math.h>

typedef struct node
{
int coe;
int power;
struct node *next;
}node;
void main()
{
node *head,*p;
int x,val=0;
int i,n;
clrscr();
printf("enter the value of n=");
scanf("%d",&n);
head=(node*)malloc(sizeof(node));
scanf("%d%d",&head->coe,&head->power);
head->next=NULL;
p=head;
for(i=0;i<n;i++)
{
p->next=(node*)malloc(sizeof(node));
p=p->next;
scanf("%d%d",&p->coe,&p->power);
p->next=NULL;
}
p=head;
while(p->next!=NULL)
{
printf("%dx^%d+",p->coe,p->power);
p=p->next;
}
printf("%dx^n%d",p->coe,p->power);
printf("enter the value of x");
scanf("%d",&x);
p=head;
while(p!=NULL)
{
val=val+(p->coe*pow(x,p->power));
p=p->next;
}
printf("%d",val);
getch();
}

No comments:

Post a Comment