Hie ,

Am teaching my self C++ ,this is my first attempt to code..,any ideas..

I am writting a C- program to deal with any two complex numbers.
The program must contain at least five functions
- Add – to add two complex numbers passed to it
- Subtract – subtract two complex numbers passed to it
- Multiply -to multiply two complex numbers passed to it
- Divide - to divide two complex numbers passed to it
- Display -to display a complex number

The user can enter any two complex numbers and chooses from the ‘main menu’ what operation to be
performed on the numbers (e.g. add them, subtract them …) and display the final result.

Hi Waway, Welcome to Daniweb. Here we follow a rule stating that every problem that we address must provide proof that they have really made an attempt to solve their problem.
So could you please post the code that you have come up with till now and then ask for help? Thank You :D

#include<stdio.h>


struct Complex {
float real;
float img;
};


Complex add_complex( Complex z1, Complex z2 ) {
Complex z3;
z3.real = z1.real + z2.real;
z3.img = z1.img + z2.img;
return z3;
}

int main() {
Complex z1, z2, z3;


printf( "Enter the first complex number \n");
printf( "Enter the real part " );
scanf( "%f", &z1.real );
printf( "Enter the imaginary part " );
scanf( "%f", &z1.img );


printf( "Enter the second complex number \n");
printf( "Enter the real part " );
scanf( "%f", &z2.real);
printf( "Enter the imaginary part " );
scanf( "%f", &z2.img );

z3 = add_complex( z1, z2 );
//show the sum
printf( "sum: %f + i * %f", z3.real, z3.img );

getchar();
return 0;
}

This article has been dead for over six months. Start a new discussion instead.