Pr.Pg Next Pg

Accept Complex number in form of x+iy tutorials

 

 

Example: Program to create a structure to accept a complex number in the form of x+iy and print it

 Sam Madam

// Program to create a structure to accept a complex number in the form of x+iy and print it

#include<stdio.h>

#include <conio.h>

struct complex

{

float real,imag;

};

void main()

{

complex c1,c2;

printf("\nEnter the real part for the first complex number: ");

scanf("%f",&c1.real);

printf("\nEnter the imaginary part for the first complex number: ");

scanf("%f",&c1.imag);

printf("\nEnter the real part for the second complex number: ");

scanf("%f",&c2.real);

printf("\nEnter the imaginary part for the second complex number: ");

scanf("%f",&c2.imag);

printf("\nFirst complex number: %f + i%f",c1.real,c1.imag);

printf("\nSecond complex number: %f + i%f",c2.real,c2.imag);

getch();

}

Output

Enter the real part for the first complex number: 15

 

Enter the imaginary part for the first complex number: 15.50

 

Enter the real part for the second complex number: 20.50

 

Enter the imaginary part for the second complex number: 22

 

First complex number: 15.000000 + i15.500000

Second complex number: 20.500000 + i22.000000


Pr.Pg border                                              Next Pg