/* * To input a matrix of order 2 X 3 of complex numbers(a +ib),save them in 2 separate matrices and compute the modulus * To be compiled using: gcc -lm * For example,if your filename is complex.c,compile it using: gcc -lm complex.c * @author-Karan Narain(karan@iitk.ac.in) * */ #include #include int main() { int real[2][3],imag[2][3],i,j; float mod[2][3]; printf("Enter the 2 X 3 matrix of complex numbers (real part then imaginary part of each element)\n"); for(i=0;i<2;i++) { for(j=0;j<3;j++) { //Input the real and imaginary parts and save real part in real matrix,imaginary part in imag matrix printf("Real part of element [%d][%d]: ",i,j); scanf("%d",&real[i][j]); printf("Imaginary part of element [%d][%d]: ",i,j); scanf("%d",&imag[i][j]); //compute modulus of inputted complex no and save it in mod matrix mod[i][j]=sqrt(pow(real[i][j],2)+pow(imag[i][j],2)); } } printf("The modulus matrix is\n"); //Print mod matrix for(i=0;i<2;i++) { for(j=0;j<3;j++) { printf("%f ",mod[i][j]); } printf("\n"); } return 0; }