Write a program in ‘C’ for the addition of two polynomials. Use Arrays and Structures. 10m Dec2006

By | June 23, 2014

Write a program in ‘C’ for the addition of two polynomials. Use Arrays and Structures. 10m Dec2006

#include<stdio.h>

void main()
{
int poly1[6][2],poly2[6][2],term1,term2,match,proceed,i,j;
printf(“Enter the number of terms in first polynomial : “);
scanf(“%d”,&term1);
printf(“Enter the number of terms in second polynomial : “);
scanf(“%d”,&term2);
printf(“Enter the coeff and expo of the first polynomial:\n”);
for(i=0;i<term1;i++)
{
scanf(“%d %d”,&poly1[i][0],&poly1[i][1]);
}
printf(“Enter the coeff and expo of the second polynomial:\n”);
for(i=0;i<term2;i++)
{
scanf(“%d %d”,&poly2[i][0],&poly2[i][1]);
}
printf(“The resultant polynomial after addition :\n”);
for(i=0;i<term1;i++)
{
match=0;
for(j=0;j<term2;j++)
{
if(match==0)
if(poly1[i][1]==poly2[j][1])
{
printf(“%d %d\n”,(poly1[i][0]+poly2[j][0]), poly1[i][1]);
match=1;
}
}
}
for(i=0;i<term1;i++)
{
proceed=1;
for(j=0;j<term2;j++)
{
if(proceed==1)
if(poly1[i][1]!=poly2[j][1])
proceed=1;
else
proceed=0;
}
if(proceed==1)
printf(“%d %d\n”,poly1[i][0],poly1[i][1]);
}
for(i=0;i<term2;i++)
{
proceed=1;
for(j=0;j<term1;j++)
{
if(proceed==1)
if(poly2[i][1]!=poly1[j][1])
proceed=1;
else
proceed=0;
}
if(proceed==1)
printf(“%d %d”,poly2[i][0],poly2[i][1]);
}
getch();
}

#include<stdio.h>
void main()
{
int poly1[6][2],poly2[6][2],term1,term2,match,proceed,i,j;
printf("Enter the number of terms in first polynomial : ");
scanf("%d",&term1);
printf("Enter the number of terms in second polynomial : ");
scanf("%d",&term2);
printf("Enter the coeff and expo of the first polynomial:\n");
for(i=0;i<term1;i++)
{
scanf("%d %d",&poly1[i][0],&poly1[i][1]);
}
printf("Enter the coeff and expo of the second polynomial:\n");
for(i=0;i<term2;i++)
{
scanf("%d %d",&poly2[i][0],&poly2[i][1]);
}
printf("The resultant polynomial after addition :\n");
for(i=0;i<term1;i++)
{
match=0;
for(j=0;j<term2;j++)
{
if(match==0)
if(poly1[i][1]==poly2[j][1])
{
printf("%d %d\n",(poly1[i][0]+poly2[j][0]), poly1[i][1]);
match=1;
}
}
}
for(i=0;i<term1;i++)
{
proceed=1;
for(j=0;j<term2;j++)
{
if(proceed==1)
if(poly1[i][1]!=poly2[j][1])
proceed=1;
else
proceed=0;
}
if(proceed==1)
printf("%d %d\n",poly1[i][0],poly1[i][1]);
}
for(i=0;i<term2;i++)
{
proceed=1;
for(j=0;j<term1;j++)
{
if(proceed==1)
if(poly2[i][1]!=poly1[j][1])
proceed=1;
else
proceed=0;
}
if(proceed==1)
printf("%d %d",poly2[i][0],poly2[i][1]);
}
getch();
}

Screen Shots:-

C_program_Add_Polynomial

C_program_Add_Polynomial_Output

 

 

 

Write a program in ‘C’ to check whether a given string is palindrome. Use pointers. 10m Dec2006

Solved program can be found on this link http://cssimplified.com/assignments/an-interactive-c-program-to-check-whether-the-given-string-is-a-palindrome-or-not-using-pointers

 

 

 

Leave a Reply