Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;//Program of polynomial multiplication
- #include<stdio.h>
- #include<malloc.h>
- #include<stdlib.h>
- int n,m,*p=NULL,*q=NULL;
- int *r=NULL,*g=NULL,*b=NULL;
- int z,j,y;
- static int c,d;
- void output(int *s,int z)
- {
- if (d==0)
- printf("The %dst poly is:\n",d+1);
- else
- printf("The %dnd poly is:\n",d+1);
- for (int i=z;i>=0;i--)
- {
- if (z==0)
- printf("%d",s[i]);
- else if (i==z&&n>0)
- printf("%d(x^%d)",s[i],i);
- else if (s[i]>0&&i>0)
- printf("+%d(x^%d)",s[i],i);
- else if (s[i]<0&&i>0)
- printf("%d(x^%d)",s[i],i);
- else if (i==0&&s[i]>0)
- printf("+%d",s[i]);
- else if (i==0&&s[i]<0)
- printf("%d",s[i]);
- }
- d++;
- }
- void input()
- {
- int *s=NULL;
- if (c==0)
- {
- printf("Enter degree of %dst polynomial\n",c+1);
- scanf("%d",&n);
- if (n<0)
- {
- printf("Wrong input\n");
- exit(1);
- }
- p=(int *)calloc(n+1,sizeof (int ));
- s=p;
- z=n;
- }
- else
- {
- printf("Enter degree of %dnd polynomial\n",c+1);
- scanf("%d",&m);
- if (m<0)
- {
- printf("Wrong input\n");
- exit(1);
- }
- q=(int *)calloc(m+1,sizeof (int ));
- s=q;
- z=m;
- }
- if (c==0)
- {
- printf("Enter %dst polynomial:-\n",c+1);
- }
- else
- {
- printf("Enter %dnd polynomial:-\n",c+1);
- }
- for (int i=z;i>=0;i--)
- {
- printf(" x^%d=",i);
- scanf("%d",&s[i]);
- }
- output(s,z);
- printf("\n\n");
- c+=1;
- }
- void showproduct(int k)
- {
- printf("\n\nThe product is:-\n");
- for (int i=k;i>=0;i--)
- {
- if (k==0)
- printf("%d",r[i]);
- else if (i==k&&r[k]>0)
- printf("%d(x^%d)",r[i],i);
- else if (r[i]>0&&i>0)
- printf("+%d(x^%d)",r[i],i);
- else if (r[i]<0&&i>0)
- printf("%d(x^%d)",r[i],i);
- else if (i==0&&r[i]>0)
- printf("+%d",r[i]);
- else if (i==0&&r[i]<0)
- printf("%d",r[i]);
- }
- printf("\n\n");
- }
- void product(int k,int l)
- {
- int o;
- r=(int *)calloc(k+l+1,sizeof (int ));
- o=(k+l+1);
- for (int v=k;v>=0;v--)
- {
- for (int j=l;j>=0;j--)
- {
- r[v+l]+=p[v]*q[j];
- }
- printf("%d %d \n",r[v+l],v+l);
- }
- // showproduct(o);
- }
- int main()
- {
- input();
- input();
- product(n,m);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement