Ask a Question

please send me the programme-- write a c prog to add two complex no by structure.


Administrator

on 2010-06-12 09:30:00  

#include 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; }