Sunday, March 7, 2010

A C++ Program for Division Of Complex Numbers(a+ib)/(c+jd)

**********(a+ib)/(c+jd) ***********
void main()
{
 float a,b,c,d;
 float x,y;
 clrscr();
 cout<<"\n ENTER THE REAL AND IMAGINARY PART OF 1ST COMPLEX NUMBER : ";
 cin>>a>>b;
 cout<<"\n ENTER THE REAL AND IMAGINARY PART OF 2ND COMPLEX NUMBER : ";
 cin>>c>>d;
 cout<<"\n\n THE RESULT IS : ";
 if(a==0 && b==0 && c==0 && d==0)
 {
  x=0;
  y=0;
  cout<<<"+i"<
 }

 if(d>0 && b>0 && d!=b && a!=c)
 {
  x = ((a*c)+(b*d))/((c*c)+(d*d));
  y = ((a*d)-(b*c))/((c*c)+(d*d));
  if(y>0)
  {
  cout<<<"+i"<
  }
  else if(y<0)
  {
   cout<<<"-i"<<(-y);
  }
 }
 else if(d<0 && b>0)
 {
  x = ((a*c)-(b*d))/((c*c)+(d*d));
  y = ((a*d)+(b*c))/((c*c)+(d*d));
  if(y<0)
  {
   cout<<<"-i"<<(-y);
  }
  else
  {
   cout<<<"+i"<
  }
 }
 else if(b<0 && d>0)
 {
  x = ((a*c)-(b*d))/((c*c)+(d*d));
  y = ((a*d)+(b*c))/((c*c)+(d*d));
  if(y<0)
  {
   cout<<<"+i"<<(-y);
  }
  else
  {
   cout<<<"-i"<
  }
 }
 else if(b<0 && d<0)
 {
  x = ((a*c)+(b*d))/((c*c)+(d*d));
  y = ((a*d)-(b*c))/((c*c)+(d*d));
  if(y<0)
  {
   cout<<<"-i"<<(-y);
  }
  else
  {
   cout<<<"+i"<
  }
 }
 else if(a==c && b==d)
 {
  cout<<"1";
 }
 getch();
 return;
}

No comments:

Post a Comment