0% found this document useful (0 votes)
5 views2 pages

Complex

The document contains a C program that performs operations on complex numbers, including addition, subtraction, multiplication, and division. It defines a structure for complex numbers and provides functions to carry out the operations based on user input. The program runs in a loop, allowing the user to perform multiple operations until they choose to exit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Complex

The document contains a C program that performs operations on complex numbers, including addition, subtraction, multiplication, and division. It defines a structure for complex numbers and provides functions to carry out the operations based on user input. The program runs in a loop, allowing the user to perform multiple operations until they choose to exit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

-----------------------------

complex numbers operations


----------------------------

#include <stdio.h>
#include<math.h>
struct complex
{
int real,imag;
};
typedef struct complex complex;
void add( complex , complex , complex );
void sub( complex , complex , complex );
void mult(complex a, complex b, complex c);
void div(complex a, complex b, complex c);
int main()
{
int ch;
complex a;
complex b;
complex c;
do{
printf("\n ENTER THE COMPLEX NUMBER ONE::::");
scanf("%d %d",&a.real,&a.imag);

printf("\n ENTER THE COMPLEX NUMBER two::::");


scanf("%d %d",&b.real,&b.imag);

printf("\n1-->add\n2-->sub\n3....>mult\n4--->div");
printf("\n enter the choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:add(a,b,c);
break;
case 2:sub(a,b,c);
break;
case 3:mult(a,b,c);
break;
case 4:div(a,b,c);
break;
default:printf("\ninvalid:::::");
break;
}
printf("\n do you wNT TO CONTINUE(PRESS 1 )::");
scanf("%d",&ch);
}while(ch==1);

return 0;
}
void add( complex a, complex b, complex c)
{
c.real=a.real+b.real;
c.imag=a.imag+b.imag;
if(c.imag>=0)
printf("\n%d+i%d",c.real,c.imag);
else
printf("\n%d %di",c.real,c.imag);
}
void sub( complex a, complex b, complex c)
{
c.real=a.real-b.real;
c.imag=a.imag-b.imag;
if(c.imag>=0)
printf("\n%d+i%d",c.real,c.imag);
else
printf("\n%d %di",c.real,c.imag);
}
void mult(complex a, complex b, complex c)
{
c.real=a.real*b.real-a.imag*b.imag;
c.imag=a.imag*b.real+a.real*b.imag;
if(c.imag>=0)
printf("\n%d+i%d",c.real,c.imag);
else
printf("\n%d %di",c.real,c.imag);
}
void div(complex a, complex b, complex c)
{
c.real = (a.real * b.real + a.imag * b.imag) / (b.real * b.real + b.imag *
b.imag);
c.imag = (a.imag * b.real - a.real * b.imag) / (b.real * b.real + b.imag *
b.imag);
if(c.imag>=0)
printf("\n%d+i%d",c.real,c.imag);
else
printf("\n%d %di",c.real,c.imag);
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy