Help With Complex Number Calculator

This is a discussion on Help With Complex Number Calculator within the C Programming forums, part of the General Programming Boards category; Code: #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) ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    3

    Help With Complex Number Calculator

    Code:
    #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;
    }
    I was wondering how you would put do multiplication , division, and computation of the conjugate? Help Please
    Last edited by kchadha; 11-07-2011 at 08:43 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,628
    This sounds like mostly a question of mathematics. In terms of programming, you can make it easier by defining a complex number struct. (Note that <complex.h> is provided by the C standard library, though I think it is only from the 1999 edition of the C standard.)
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    3
    right, but how would u do that? i need like an example . I'm new to this sorry :/

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,628
    As in the struct? It could be as simple as:
    Code:
    struct Complex
    {
        int real;
        int imaginary;
    };
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Complex Number
    By figura in forum C Programming
    Replies: 12
    Last Post: 04-14-2011, 06:01 PM
  2. complex calculator
    By rafay_07 in forum C++ Programming
    Replies: 16
    Last Post: 11-07-2010, 03:40 AM
  3. Complex Number Class
    By Sephiroth1109 in forum C++ Programming
    Replies: 15
    Last Post: 12-12-2007, 03:46 PM
  4. complex.h calculator
    By devil-in-me in forum C++ Programming
    Replies: 1
    Last Post: 11-03-2007, 11:22 PM
  5. complex number arithmetic
    By Micko in forum C++ Programming
    Replies: 1
    Last Post: 12-10-2003, 08:04 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21