===========================================================================
CODING
#include<all.h>
void main()
{
label:
clrscr();
float n,w,Theta,a,b,c,d,r,x,h;
char ch;
cout<<"\nComplex Calculator Fuctions:-";
cout<<"\n Add.: 1 Sub.: 5";
cout<<"\n Multiply: 2 Divide: 6";
cout<<"\n Conjugate: 3 Pol(z): 7";
cout<<"\n Sqrt.: 4 ";
cout<<"\n\n ¯Enter number of Function: ";
cin>>n;
if(n<=7);
else
{
cout<<"Wrong Input!\n Try Again?(y/n): ";
cin>>ch;
if(ch=='y' || ch=='Y')
goto label;
else
exit(0);
}
clrscr();
if(n==1 || n==5 || n==2 || n==6)
{
cout<<"1st Complex Number(a+ib):-";
cout<<"\n Enter real part: ";
cin>>a;
cout<<"\n Enter imaginary part: ";
cin>>b;
cout<<"\n2nd Complex Number(c+id):-";
cout<<"\n Enter real part: ";
cin>>c;
cout<<"\n Enter imaginary part: ";
cin>>d;
}
else
{
cout<<"Complex Number(a+ib):-";
cout<<"\n Enter real part: ";
cin>>a;
cout<<"\n Enter imaginary part: ";
cin>>b;
}
if(n==1)
{
a=a+c;
b=b+d;
}
else if(n==2)
{
x=a;
a=a*c-b*d;
b=x*d+b*c;
}
else if(n==3)
{
a=a;
b=-b;
}
else if(n==4)
{
x=a;
h=b;
a=sqrt((a+sqrt(a*a+b*b))/2);
b=sqrt((x+sqrt(x*x+b*b))/2-x);
if(x*h<0)
b=-b;
}
else if(n==5)
{
a=a-c;
b=b-d;
}
else if(n==6)
{
x=a;
if(c*c+d*d==0)
{
a=0;
b=0;
}
else
{
a=(a*c+b*d)/(c*c+d*d);
b=(b*c-x*d)/(c*c+d*d);
}
}
else if(n==7)
{
r=sqrt(a*a+b*b);
Theta=atan(fabs(b)/fabs(a))*180/M_PI;
if(a>=0 && b>=0)
{
w=1;
Theta=Theta;
}
else if(a<0 && b>=0)
{
w=2;
Theta=180-Theta;
}
else if(a<0 && b<0)
{
w=3;
Theta=180+Theta;
}
else if(a>=0 && b<0)
{
w=4;
Theta=360-Theta;
}
}
if(n==7)
{
cout<<"\n\n\n\t\t\tResult: "<<r<<"*[cos("<<Theta<<") + i*sin("<<Theta<<")]\nQuadrant: "<<w;
}
else
{
if(b>=0)
cout<<"\n\n\n\t\t\tResult: "<<a<<"+"<<b<<"i";
else
cout<<"\n\n\n\t\t\tResult: "<<a<<b<<"i";
}
getch();
}
CODING
#include<all.h>
void main()
{
label:
clrscr();
float n,w,Theta,a,b,c,d,r,x,h;
char ch;
cout<<"\nComplex Calculator Fuctions:-";
cout<<"\n Add.: 1 Sub.: 5";
cout<<"\n Multiply: 2 Divide: 6";
cout<<"\n Conjugate: 3 Pol(z): 7";
cout<<"\n Sqrt.: 4 ";
cout<<"\n\n ¯Enter number of Function: ";
cin>>n;
if(n<=7);
else
{
cout<<"Wrong Input!\n Try Again?(y/n): ";
cin>>ch;
if(ch=='y' || ch=='Y')
goto label;
else
exit(0);
}
clrscr();
if(n==1 || n==5 || n==2 || n==6)
{
cout<<"1st Complex Number(a+ib):-";
cout<<"\n Enter real part: ";
cin>>a;
cout<<"\n Enter imaginary part: ";
cin>>b;
cout<<"\n2nd Complex Number(c+id):-";
cout<<"\n Enter real part: ";
cin>>c;
cout<<"\n Enter imaginary part: ";
cin>>d;
}
else
{
cout<<"Complex Number(a+ib):-";
cout<<"\n Enter real part: ";
cin>>a;
cout<<"\n Enter imaginary part: ";
cin>>b;
}
if(n==1)
{
a=a+c;
b=b+d;
}
else if(n==2)
{
x=a;
a=a*c-b*d;
b=x*d+b*c;
}
else if(n==3)
{
a=a;
b=-b;
}
else if(n==4)
{
x=a;
h=b;
a=sqrt((a+sqrt(a*a+b*b))/2);
b=sqrt((x+sqrt(x*x+b*b))/2-x);
if(x*h<0)
b=-b;
}
else if(n==5)
{
a=a-c;
b=b-d;
}
else if(n==6)
{
x=a;
if(c*c+d*d==0)
{
a=0;
b=0;
}
else
{
a=(a*c+b*d)/(c*c+d*d);
b=(b*c-x*d)/(c*c+d*d);
}
}
else if(n==7)
{
r=sqrt(a*a+b*b);
Theta=atan(fabs(b)/fabs(a))*180/M_PI;
if(a>=0 && b>=0)
{
w=1;
Theta=Theta;
}
else if(a<0 && b>=0)
{
w=2;
Theta=180-Theta;
}
else if(a<0 && b<0)
{
w=3;
Theta=180+Theta;
}
else if(a>=0 && b<0)
{
w=4;
Theta=360-Theta;
}
}
if(n==7)
{
cout<<"\n\n\n\t\t\tResult: "<<r<<"*[cos("<<Theta<<") + i*sin("<<Theta<<")]\nQuadrant: "<<w;
}
else
{
if(b>=0)
cout<<"\n\n\n\t\t\tResult: "<<a<<"+"<<b<<"i";
else
cout<<"\n\n\n\t\t\tResult: "<<a<<b<<"i";
}
getch();
}
===========================================================================
No comments:
Post a Comment