Addition and substraction of polynomials is working fine but the multiplication isn't
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define MAX 20
void init(int p[]);
void read(int p1[],int p2[]);
void print(int p[]);
void add(int p1[],int p2[],int p3[]);
void sub(int p1[],int p2[],int p3[]);
void multiply(int p1[],int p2[],int p3[]);
void main()
{
int p1[MAX],p2[MAX],p3[MAX];
int choice;
do
{
printf("\n 1. Creation of polynomials ");
printf("\n 2. Addition of polynomials ");
printf("\n 3. Substraction of polynomials ");
printf("\n 4. Multiplication of polynomials ");
printf("\n 5. EXIT ");
printf("\n 1. Please enter your choice ");
scanf("%d",&choice);
switch(choice)
{
case 1 : read(p1,p2);
break;
case 2 : add(p1,p2,p3);
printf("\n 1st Polynomial ");
print(p1);
printf("\n 2nd Polynomial ");
print(p2);
printf("\n Sum of given polynomials : ");
print(p3);
break;
case 3 : sub(p1,p2,p3);
printf("\n 1st Polynomial ");
print(p1);
printf("\n 2nd Polynomial ");
print(p2);
printf("\n Substraction of given polynomials : ");
print(p3);
break;
case 4 : multiply(p1,p2,p3);
printf("\n 1st Polynomial ");
print(p1);
printf("\n 2nd Polynomial ");
print(p2);
printf("\n Multiplication of given polynomials : ");
print(p3);
break;
}
}
while(choice!=5);
}
void read(int p1[],int p2[])
{
int n,i,power1,coeff1,power2,coeff2;
init(p1);
printf("\n Enter number of terms : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter the First term (power,coefficient) ");
scanf("%d%d",&power1,&coeff1);
p1[power1]=coeff1;
}
init(p2);
printf("\n Enter number of terms : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter the Second term (power,coefficient) ");
scanf("%d%d",&power2,&coeff2);
p2[power2]=coeff2;
}
}
void init(int p[])
{
int i;
for(i=0;i<MAX;i++)
p[i]=0;
}
void add(int p1[],int p2[],int p3[])
{
int i;
for(i=0;i<MAX;i++)
p3[i]=p1[i] + p2[i];
}
void sub(int p1[],int p2[],int p3[])
{
int i;
for(i=0;i<MAX;i++)
p3[i]=p1[i] - p2[i];
}
void multiply(int p1[],int p2[],int p3[])
{
int i,j,k;
for( i=0; i<=MAX; i++)
for( j=0; j<=MAX; j++)
k=i+j;
p3[k] = p3[k]+p1[i]*p2[j];
}
void print(int p[])
{
int i;
for(i=0;i<MAX;i++)
if(p[i]!=0)
printf("%dX^%d ",p[i],i);
}