Thread: help with this would meen alot

  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    1

    help with this would meen alot

    Hi guys. I'm revising for an exam i have in a few weeks. I'm an electrical engineer and i struggle a fair bit with C programming. This question has popped up on a few of the past exams, so it may come up again. It asks for code to be inserted so that the outcome displays "x" for the user. I have no idea how to do it, even after scouring my notes. Any help would be greatly appreciated. thanks


    Code:
    struct Complex {float real; float imaginary;}; 
                struct Complex Add(struct Complex a, struct Complex b);
                void main()
                {                   struct Complex a,b,x;
                                    a.real=10;
                                    a.imaginary=10;
                                    b.real=30;
                                    b.imaginary=40;
                                    x=Multiply(a,b);
    
                                   /// add code here to display x for the user                 }***
     
                struct Complex Multiply(struct Complex a, struct Complex b)
                                    {                   
                                     struct Complex c;   
                                    c.real=a.real*b.real- a.imaginary*b.imaginary;
                                    c.imaginary= a.real* b.imaginary + a.imaginary *b.real;
                                    return (c);                                        
                                     }

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    use something like printf("real:%f imag:%f\n",x.real,x.imaginary);

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    First main() should be defined to return an int and you should return an int from this function.

    Second you are missing the closing brace for the function main:

    Code:
    int main
    {
    
       return(0);
    }
    Next would a simple printf() satisfy the objectives?

    Jim

  4. #4
    Registered User
    Join Date
    Mar 2012
    Location
    the c - side
    Posts
    373
    It's a duff question. The prototype is for an Add function instead of the presented Multiply.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I'm having alot of trouble
    By LAURENT* in forum C++ Programming
    Replies: 4
    Last Post: 01-14-2013, 09:10 PM
  2. Replies: 2
    Last Post: 01-23-2011, 01:40 PM
  3. alot?
    By Yarin in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 07-08-2008, 07:36 PM
  4. storing alot of variables...
    By MikeyIckey in forum C Programming
    Replies: 11
    Last Post: 05-30-2008, 12:31 PM
  5. Replies: 6
    Last Post: 08-18-2002, 08:01 AM