#include<stdio.h>
#include<malloc.h>
int* getpoly(int);
void showpoly(int *,int);
int* addpoly(int *,int,int *,int);
int* mulpoly(int *,int,int *,int);
int main(void)
{
int *p1,*p2,*p3,d1,d2,d3;
/*get poly*/
printf("\nEnter the degree of the 1st polynomial:");
scanf("%d",&d1);
p1=getpoly(d1);
printf("\nEnter the degree of the 2nd polynomial:");
scanf("%d",&d2);
p2=getpoly(d2);
printf("Polynomials entered are\n\n");
showpoly(p1,d1);
printf("and\n\n");
showpoly(p2,d2);
/*compute the sum*/
d3=(d1>=d2?d1:d2);
p3=addpoly(p1,d1,p2,d2);
printf("Sum of the polynomials is:\n");
showpoly(p3,d3);
/*compute product*/
p3=mulpoly(p1,d1,p2,d2);
printf("Product of the polynomials is:\n");
showpoly(p3,d1+d2);
}
int* getpoly(int degree)
{
int i,*p;
p=malloc((1+degree)*sizeof(int));
for(i=0;i<=degree;i++)
{
printf("\nEnter coefficient of x^%d:",i);
scanf("%d",(p+i));
}
return(p);
}
void showpoly(int *p,int degree)
{
int i;
for(i=0;i<=degree;i++)
printf("%dx^%d + ",*(p+i),i);
printf("\b\b\b ");
printf("\n");
}
int* addpoly(int *p1,int d1,int *p2,int d2)
{
int i,degree,*p;
degree=(d1>=d2?d1:d2);
p=malloc((1+degree)*sizeof(int));
for (i=0;i<=degree;i++)
if((i>d1) && (i<=d2))
*(p+i)=*(p2+i);
else if((i>d2) && (i<=d1))
*(p+i)=*(p1+i);
else
*(p+i)=*(p1+i)+*(p2+i);
return(p);
}
int* mulpoly(int *p1,int d1,int*p2,int d2)/* this is the function of concern*/
{
int i,j,*p;
p=malloc((1+d1+d2)*sizeof(int));
for(i=0;i<=d1;i++)
for(j=0;j<=d2;j++)
p[i+j]+=p1[i]*p2[j];
return(p);
}
Reference:cprogramming-bd.com/c_page1.aspx# array programming
How to write a program for mouse in microprocessor?
To write a C++ program to display the student details using class and array of object.
int findMax(int *array) { int max = array[0]; for(int i = 1; i < array.length(); i++) { if(array[i] > max) max = array[i] } return max; }
maxValue = function (array) {mxm = array[0];for (i=0; i<array.length; i++) {if (array[i]>mxm) {mxm = array[i];}}return mxm;}; i don't know
Reference:cprogramming-bd.com/c_page1.aspx# array programming
How to write a program for mouse in microprocessor?
To write a C++ program to display the student details using class and array of object.
write an assembly language program to find sum of N numbers
array type
int findMax(int *array) { int max = array[0]; for(int i = 1; i < array.length(); i++) { if(array[i] > max) max = array[i] } return max; }
maxValue = function (array) {mxm = array[0];for (i=0; i<array.length; i++) {if (array[i]>mxm) {mxm = array[i];}}return mxm;}; i don't know
public static int[] reverseArray(int[] array) { int i = 0, j = array.length - 1; for (i = 0; i < array.length / 2; i++, j--) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; }
You need to specify the language in which you want the subtraction of the two matrix in two dimension array written.
The matrix multiplication in c language : c program is used to multiply matrices with two dimensional array. This program multiplies two matrices which will be entered by the user.
If you are using an array : sort using qsort() then take middle element.
you can write by two ways 1 by giving the size of array at declaration 2 by checking condition