I am studing SE computer engg,i have a problem in above code execution plz some help me

Recommended Answers

All 3 Replies

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

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.

There is a C forum for C code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.