Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.facebook.com/AminproPastebin
- #include <stdio.h>
- struct Complex{
- float real;
- float imag;
- };
- //Function Prototypes
- struct Complex complex_add(struct Complex, struct Complex);
- void complex_mul(struct Complex, struct Complex, struct Complex *);
- int main(void){
- struct Complex z1, z2, add, mul;
- //user input
- printf("First complex number...\n");
- printf("Enter the real part: \n");
- scanf("%f", &z1.real);
- printf("Enter the imaginary part: \n");
- scanf("%f", &z1.imag);
- printf("Second complex number...\n");
- printf("Enter the real part: \n");
- scanf("%f", &z2.real);
- printf("Enter the imaginary part: \n");
- scanf("%f", &z2.imag);
- //calling function
- add = complex_add(z1, z2);
- complex_mul(z1, z2, &mul);
- //print
- printf("addition result: %.2f%+.2fi\n", add.real, add.imag);
- printf("Multiplication result: %.2f%+.2fi\n", mul.real, mul.imag);
- return 0;
- }
- //function definition
- struct Complex complex_add(struct Complex n1, struct Complex n2){
- struct Complex result;
- result.real = n1.real + n2.real;
- result.imag = n1.imag + n2.imag;
- return result;
- }
- void complex_mul(struct Complex n1, struct Complex n2,
- struct Complex *result){
- result -> real = (n1.real*n2.real) - (n1.imag*n2.imag);
- result -> imag = (n1.real*n2.imag) + (n1.imag*n2.real);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement