c code for division of two complex numbers










#include<stdio.h>
typedef struct{
        float a;
        float b;
}Complex;
Complex divide(Complex,Complex);
int main(){
    float a1,b1,a2,b2;
    Complex x,y,z;
    printf("Enter first complex number : ");
    scanf("%f+%fi",&a1,&b1);
    printf("\nEnter second complex number : ");
    scanf("%f+%fi",&a2,&b2);
    x.a = a1; x.b = b1;
    y.a = a2; y.b = b2;
    z = divide(x,y);
    printf("After division: %f+%fi",z.a,z.b);
    return 0;
}
Complex divide(Complex x,Complex y){
    Complex z;
    z.a = (x.a*y.a + x.b*y.b)/(y.a*y.a+y.b*y.b);
    z.b = (x.b*y.a - x.a*y.b)/(y.a*y.a + y.b*y.b);
    return z;
}





Alogrithm:
**




Post a Comment