Write a Menu Driven Program in C For - -Addition of two Polynomial. -Evaluation of an accepted polynomial.


#include

#include

#include

void addpoly();

void evalpoly();

void main()

{

int ch;

clrscr();

while(1)

{

printf("\n 1.Addition of two Polynomial.");

printf("\n 2.Evaluation of an accepted polynomial.");

printf("\n 3.Exit.");

printf("\n Enter Your Choice: ");

scanf("%d",&ch);

switch(ch)

{

case 1:addpoly();

break;

case 2:evalpoly();

break;

case 3:exit(0);

default:

printf("\n Invalid Choice.");

}

}

}

void addpoly()

{

int a[10],b[10],c[20],t,i;

printf("\n How Many Degree:");

scanf("%d",&t);

printf("\n Enter The Polynomial Order For A:");

for(i=t;i>=0;i--)

{

printf("\n Enter Coeff of Degree x^%d: ",i);

scanf("%d",&a[i]);

}

printf("\n Enter The Polynomial Order For B:");

for(i=t;i>=0;i--)

{

printf("\n Enter Coeff of Degree x^%d: ",i);

scanf("%d",&b[i]);

}

printf("\n Polynomial A is ");

for(i=t;i>0;i--)

{

printf("%dx%d+",a[i],i);

}

printf("%dx%d",a[i],i);

printf("\n Polynomial B is ");

for(i=t;i>0;i--)

{

printf("%dx%d+",b[i],i);

}

printf("%dx%d",b[i],i);

for(i=t;i>=0;i--)

{

c[i]=a[i]+b[i];

}

printf("\n ADDITION IS : ");

for(i=t;i>0;i--)

{

printf("%dx%d+",c[i],i);

}

printf("%dx%d",c[i],i);

}




void evalpoly()

{

int a[10],t,i,x,ans=0;

printf("\n Enter The Degree of Polynomial:");

scanf("%d",&t);

printf("\n Enter The Polynomial Order");

for(i=t;i>=0;i--)

{

printf("\n Enter The Coeff of Degree %d^: ",i);

scanf("%d",&a[i]);

}

printf("\n The Polynomial is: ");

for(i=t;i>0;i--)

{

printf("%dx%d+",a[i],i);

}

printf("%dx%d",a[i],i);


printf("\n Enter The Variable:");

scanf("%d",&x);

for(i=t;i>=0;i--)

{

ans=ans+a[i]*pow(x,i);

}

printf("\n Result is %d",ans);

}


/*OUTPUT


 1.Addition of two Polynomial.

 2.Evaluation of an accepted polynomial.

 3.Exit.

 Enter Your Choice: 1


 How Many Degree:2


 Enter The Polynomial Order For A:

 Enter Coeff of Degree x^2: 5


 Enter Coeff of Degree x^1: 4


 Enter Coeff of Degree x^0: 6


 Enter The Polynomial Order For B:

 Enter Coeff of Degree x^2: 2


 Enter Coeff of Degree x^1: 1


 Enter Coeff of Degree x^0: 3


 Polynomial A is 5x2+4x1+6x0

 Polynomial B is 2x2+1x1+3x0

 ADDITION IS : 7x2+5x1+9x0


 1.Addition of two Polynomial.

 2.Evaluation of an accepted polynomial.

 3.Exit.

 Enter Your Choice: 2


 Enter The Degree of Polynomial:2


 Enter The Polynomial Order

 Enter The Coeff of Degree 2^: 2


 Enter The Coeff of Degree 1^: 3


 Enter The Coeff of Degree 0^: 4


 The Polynomial is: 2x2+3x1+4x0

 Enter The Variable:2


 Result is 18


 1.Addition of two Polynomial.

 2.Evaluation of an accepted polynomial.

 3.Exit.

 Enter Your Choice: 1


 How Many Degree:5


 Enter The Polynomial Order For A:

 Enter Coeff of Degree x^5: 2


 Enter Coeff of Degree x^4: 1


 Enter Coeff of Degree x^3: 4


 Enter Coeff of Degree x^2: 6


 Enter Coeff of Degree x^1: 8


 Enter Coeff of Degree x^0: 7


 Enter The Polynomial Order For B:

 Enter Coeff of Degree x^5: 2


 Enter Coeff of Degree x^4: 4


 Enter Coeff of Degree x^3: 5


 Enter Coeff of Degree x^2: 6


 Enter Coeff of Degree x^1: 7


 Enter Coeff of Degree x^0: 1


 Polynomial A is 2x5+1x4+4x3+6x2+8x1+7x0

 Polynomial B is 2x5+4x4+5x3+6x2+7x1+1x0

 ADDITION IS : 4x5+5x4+9x3+12x2+15x1+8x0


 1.Addition of two Polynomial.

 2.Evaluation of an accepted polynomial.

 3.Exit.

 Enter Your Choice: 2


 Enter The Degree of Polynomial:4


 Enter The Polynomial Order

 Enter The Coeff of Degree 4^: 2


 Enter The Coeff of Degree 3^: 1


 Enter The Coeff of Degree 2^: 3


 Enter The Coeff of Degree 1^: 4


 Enter The Coeff of Degree 0^: 1


 The Polynomial is: 2x4+1x3+3x2+4x1+1x0

 Enter The Variable:3


 Result is 229

 1.Addition of two Polynomial.

 2.Evaluation of an accepted polynomial.

 3.Exit.

 Enter Your Choice: 3 */
Write a Menu Driven Program in C For - -Addition of two Polynomial. -Evaluation of an accepted polynomial. Write a Menu Driven Program in C For - -Addition of two Polynomial. -Evaluation of an accepted polynomial. Reviewed by on November 16, 2013 Rating: 5
Powered by Blogger.