To implement addition and multiplication of two 2D arrays.

#include<stdio.h>
#include<conio.h>
typedef struct complex
 {
    float real;
    float imag;
}complex;
    complex add(complex, complex);
    complex multiply(complex, complex);
    int main()
    {
        complex n1,n2,sum,mul;
        printf("\t For first complex number : \n");
        printf("Enter real and imaginary respectively :\n");
        scanf("%f%f",&n1.real,&n1.imag);
        printf("\n\t For second complex number : \n");
        printf("Enter real and imaginary respectively :\n");
        scanf("%f%f",&n2.real,&n2.imag);
        sum=add(n1,n2);
        mul=multiply(n1,n2);
        printf("\t Sum = %.1f+%.1f1",sum.real,sum.imag);
        printf("\t Multiply = %.1f+%.1f1",mul.real,mul.imag);
    }
    complex add(complex n1, complex n2)
        {
            complex temp;
            temp.real=n1.real+n2.real;
            temp.imag=n1.imag+n2.imag;
            return temp;
        }
    complex multiply(complex n1, complex n2)
        {
            complex temp;
            temp.real=n1.real*n2.real-n1.imag*n2.imag;
            temp.imag=n1.real*n2.real+n1.real*n2.real;
            return temp;
}


OUTPUT :-

Previous Post
Next Post