google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: C program in data structure for addition of two polynomial

Monday, April 6, 2015

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]);
}

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

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