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
    21,432
    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.)
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,432
    As in the struct? It could be as simple as:
    Code:
    struct Complex
    {
        int real;
        int imaginary;
    };
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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