C Program To Perform Arithmetic Operations on Complex Numbers

#include<stdio.h>
struct complex
{
float real;
float imag;
}
c,c1,c2;
void main()
{
clrscr();
printf("Enter real and imaginary parts for first number \n");
scanf("%f %f",&c1.real,&c1.imag);
printf("Enter real and imaginary parts for second number \n");
scanf("%f %f",&c2.real,&c2.imag);
printf("Addition of two complex numbers is..\n");
c.real=c1.real+c2.real;
c.imag=c1.imag+c2.imag;
printf("%f + i(%f)\n",c.real,c.imag);
printf("Subtraction of two complex numbers is..\n");
c.real=c1.real-c2.real;
c.imag=c1.imag-c2.imag;
printf("%f + i(%f)\n",c.real,c.imag);
printf("M..\n");
c.real=(c1.real*c2.real)-(c1.imag*c2.imag);
c.imag=(c1.real*c2.imag)+(c1.imag*c2.real);
printf("%f + i(%f)\n",c.real,c.imag);
getch();
}


Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

No comments:

Post a Comment