Wednesday, 26 February 2014

8:Complex number definition

Complex numbers definition
Complex numbers are two dimensional numbers i.e. it consists real part and imaginary part.
Complex numbers are written as a + ib
Where a and b are real numbers and i2 = -1
#include<stdio.h>
int main(){
int a,b;
printf("Enter the real part of complex number: ");
scanf("%d",&a);
printf("Enter the imaginary part of complex number: ");
scanf("%d",&b);
printf("\nComplex number is: %d%+di",a,b );
return 0;
}
Operation on complex numbers:
Addition of complex number
(a + ib) + (c + id) = (a+c) + i(b+d)
Subtraction of complex numbers
(a + ib) -(c + id) = (a+c) + i(b-d)
Multiplication of complex numbers
(a + ib) *(c + id) = (ac-bd) + i(bc+ad)
Divison of complex numbers
(a + ib) / c + id) = ((ac + bd) + i(bc-ad))/(c2 + d2)

//ADDITION & SUBTRACTION OF TWO COMPLEX NUMBERS USING C PROGRAM
#include<stdio.h>
int main(){
  int a,b,c,d,x,y;
  printf("\nEnter the first complex number:");
  scanf("%d%d",&a,&b);
  printf("\nEnter the second complex number:");
  scanf("%d%d",&c,&d);
  if(b<0)
      printf("%d-i\n",a-b);
  else
      printf("d+i\n",a+b);
  if(d<0)
      printf("d-i\n",c-d);
  else
      printf("%d+i\n",c+d);
  printf("\nADDITION ");
  x=a+c;
  y=b+d;
  if(y>0)
      printf("%d-i%d",x,-y);
  else
      printf("%d+i%d",x,+y);
  printf("\n\nSUBTRACTION ");
  x=a-c;
  y=b-d;
  if(y<0)
      printf("%d-i%d",x,-y);
  else
      printf("%d+i%d",x,+y);
  return 0;
}

No comments:

Post a Comment