google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.

Monday, April 6, 2015

C program for multiplication of two polynomial in data structure

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[10],b[10],c[10];
 int i,j,n,k,power,coeff;
 clrscr();
 for(i=0;i<10;i++)
 {
  a[i]=0;
  b[i]=0;
  c[i]=0;
 }
 printf("\n first polynomel");
 printf("\n enter number of terms=");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  printf("\n enter coefficient=");
  scanf("%d",&coeff);
  printf("\n enter power");
  scanf("%d",&power);
  a[power]=coeff;
 }
 printf("\n second polynomel");
 printf("\n enter number of terms=");
 scanf("%d",&k);
 for(i=0;i<k;i++)
 {
  printf("\n enter coefficient=");
  scanf("%d",&coeff);
  printf("\n enter power");
  scanf("%d",&power);
  b[power]=coeff;
 }
 for(i=9;i>=0;i--)
 {
  if(a[i]!=0)
  {
   for(j=9;j>=0;j--)
   {
    if(b[j]!=0)
    {
     c[i+j]=c[i+j]+a[i]*b[j];
    }
   }
  }
 }
 printf("\n our results is=");
 for(i=9;i>=0;i--)
 {
  if(c[i]!=0)
  {
   if(i!=0)
   {
    printf("%dx^%d+",c[i],i);
   }
   else
   {
    printf("%dx^%d",c[i],i);
   }
  }
 }
 getch();
}

C program in data structure for addition of two polynomial

#include<stdio.h>
#include<conio.h>
void show(int p[]);
void main()
{
 int a[10],b[10],c[10];
 int n,k,i,p,coeff;
 clrscr();
 for(i=0;i<10;i++)
 {
  a[i]=0;
  b[i]=0;
  c[i]=0;
 }
 printf("\n First polynomial");
 printf("\n Enter number of terms=");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  printf("\n Enter power & coefficient=");
  scanf("%d%d",&p,&coeff);
  a[p]=coeff;
 }
 printf("\n Second polynomial");
 printf("\n Enter number of terms=");
 scanf("%d",&k);
 for(i=0;i<k;i++)
 {
  printf("\n Enter power & coefficient=");
  scanf("%d%d",&p,&coeff);
  b[p]=coeff;
 }
 printf("\n First polynomial is:-\n\n");
 show(a);
 printf("\n Second polynomial is:-\n\n");
 show(b);
 for(i=0;i<10;i++)
 {
  c[i]=a[i]+b[i];
 }
 printf("\n Addition of two polynomials is=\n\n");
 show(c);
 getch();
}
void show(int p[])
{
  int i;
  for(i=9;i>0;i--)
  {
   if(p[i]!=0)
   {
    printf("%dx^%d+",p[i],i);
   }
  }
  printf("%d",p[i]);
}

अच्छे विचार करे विचार

  पहचान की नुमाईश, जरा कम करें... जहाँ भी "मैं" लिखा है, उसे "हम" करें... हमारी "इच्छाओं" से ज़्यादा "सुन...