TAB

One of the works done by our Robotics and Machine Learning division,
SELF-LEVELING QUADCOPTER
Arduino based Quadcopter.
Self-leveling is acheived by the aligning the quadcopter using the readings from the gryo as well as the accelerometer.
A four channel RC transmitter is used to control the movement of the quadcopter when in flight. Kindly subscribe to our YouTube Channel and stay tuned.

Tuesday 26 January 2016

PRACTICE PROBLEM 2(24-1 to 31-1):COMPLEX NUMBERS

I had to forcefully format the output in the required manner.
For example it had to be +i and not +1i ..
So not much logic in this problem except for the calculation.
========================================================================


#include<stdio.h>
void add(int,int,int,int);
void sub(int,int,int,int);
void mul(int,int,int,int);
int main()
{
  int a,b,c,d;
  scanf("%d\n%d\n%d\n%d",&a,&b,&c,&d);
  add(a,b,c,d);
  sub(a,b,c,d);
  mul(a,b,c,d);

  return 0;

}
void add(int a,int b,int c,int d)
{
  if(b+d==1)
  printf("%d+i\n",a+c);
  else if(b+d==-1)
  printf("%d-i\n",a+c);
  else if(b+d>=0)
  printf("%d+%di\n",a+c,b+d);
  else
  printf("%d%di\n",a+c,b+d);
}
void sub(int a,int b,int c,int d)
{
  if(b-d==1)
  printf("%d+i",a-c);
  else if(b-d==-1)
  printf("%d-i",a-c);
  else if(b-d>=0)
  printf("%d+%di\n",a-c,b-d);
  else
  printf("%d%di\n",a-c,b-d);
}
void mul(int a,int b,int c,int d)
{
  if(a*d+b*c==1)
  printf("%d+i",a*c-b*d);
  else if(a*d+b*c==-1)
  printf("%d-i",a*c-b*d);
  else if(a*d+b*c>=0)
  printf("%d+%di",a*c-b*d,a*d+b*c);
  else
  printf("%d%di",a*c-b*d,a*d+b*c);

}

1 comment:

  1. in the complex number code if the value with i is 0 than according to ur code it will print 0i
    eg if the real value is 2 and imaginery value is 0 than according to ur code it will print 20i
    but it is wrong

    ReplyDelete