3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by dmanw100
0
#include<stdio.h>
#include<conio.h>
int n,m;
//void add();
  struct poly
     {
     int c,p;
     }x1[30],x2[30],x3[30];
void create(int,struct poly x[]);
void display(int,struct poly x[]);
void add(struct poly x1[],struct poly x2[],int n,int m);
void main()
     {
      int a,b,c,cho;
      clrscr();
      printf("\ndisplay\nadd");
      scanf("%d",&cho);
      switch(cho)
	{
	 case 1:printf("enter no");
		scanf("%d",&n);
		create(n,x1);
		display(n,x1);
		break;
	 case 2:printf("enter no of terms");
		scanf("%d",&n);
		create(n,x1);
		display(n,x1);
		printf("enter no of terms");
		scanf("%d",&m);
		create(m,x2);
		display(m,x2);
		add(x1,x2,n,m);
		break;
	}
	getch();
     }


void display(int s,struct poly x[])
     {
     int i;
     printf("\n");
     for(i=0;i<s;i++)
       {
       printf("%dx^%d+",x[i].c,x[i].p);
       }
     printf("\n");
     }
void create(int r,struct poly x[])
     {
      int i;
      for(i=0;i<r;i++)
	{
	 scanf("%d%d",&x[i].p,&x[i].c);
	}
     }
void add(struct poly x1[],struct poly x2[],int n,int m)
     {
     int i,j,k,flag;
     i=j=k=0;
     while(i<n)
	 {
	 while(i<m)
	  {
	   if(x1[i].p==x2[i].p)
	     {
	     x3[k].p=x1[i].p;
	     x3[k].c=x1[i].c+x2[i].c;
	     k++;i++;j++;//break;
	     }
	    else
	     {if(x1[i].p>x2[i].p)
	       { x3[k].p=x1[i].p;
		 x3[k].c=x1[i].c;
		 k++;//break;
	       }
	      else
	       {if(x1[i].p<x2[i].p)
		 { x3[k].p=x1[j].p;
		   x3[k].c=x1[j].c;
		   k++;//break;
		 }
	       }
	     }break;
	  }
	 }
	 display(k,x3);
    }
Attachments
#include<stdio.h>
#include<conio.h>
int n,m;
//void add();
  struct poly
     {
     int c,p;
     }x1[30],x2[30],x3[30];
void create(int,struct poly x[]);
void display(int,struct poly x[]);
void add(struct poly x1[],struct poly x2[],int n,int m);
void main()
     {
      int a,b,c,cho;
      clrscr();
      printf("\ndisplay\nadd");
      scanf("%d",&cho);
      switch(cho)
	{
	 case 1:printf("enter no");
		scanf("%d",&n);
		create(n,x1);
		display(n,x1);
		break;
	 case 2:printf("enter no of terms");
		scanf("%d",&n);
		create(n,x1);
		display(n,x1);
		printf("enter no of terms");
		scanf("%d",&m);
		create(m,x2);
		display(m,x2);
		add(x1,x2,n,m);
		break;
	}
	getch();
     }


void display(int s,struct poly x[])
     {
     int i;
     printf("\n");
     for(i=0;i<s;i++)
       {
       printf("%dx^%d+",x[i].c,x[i].p);
       }
     printf("\n");
     }
void create(int r,struct poly x[])
     {
      int i;
      for(i=0;i<r;i++)
	{
	 scanf("%d%d",&x[i].p,&x[i].c);
	}
     }
void add(struct poly x1[],struct poly x2[],int n,int m)
     {
     int i,j,k,flag;
     i=j=k=0;
     while(i<n)
	 {
	 while(i<m)
	  {
	   if(x1[i].p==x2[i].p)
	     {
	     x3[k].p=x1[i].p;
	     x3[k].c=x1[i].c+x2[i].c;
	     k++;i++;j++;//break;
	     }
	    else
	     {if(x1[i].p>x2[i].p)
	       { x3[k].p=x1[i].p;
		 x3[k].c=x1[i].c;
		 k++;//break;
	       }
	      else
	       {if(x1[i].p<x2[i].p)
		 { x3[k].p=x1[j].p;
		   x3[k].c=x1[j].c;
		   k++;//break;
		 }
	       }
	     }break;
	  }
	 }
	 display(k,x3);
    }
0

You are going to have to tell us what's wrong (in detail) before anyone can help you. Just telling us "my program's broke" is like taking your car to the auto repair shop and telling the repairman "my car's broke". We need a lot more information than that.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.