Thread: Multiplication Code

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    14

    Post Correct code for multiplication table

    //please provide code for multiplication table
    Anna

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Please provide your code attempts before we offer help.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    14

    Multiplication Code

    CODE
    //multiplication table for the number 0<=10


    #include <stdio.h>
    int main()

    int num, product;

    for( num = 0; num<=10: num++ ) {

    for( product = 1;

    product = 0 * num);

    }

    printf( "product is %d/n", product);

    return 0;

    }

    /Code
    Anna

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Close.... have a look at this version which is based on your conventions:
    Code:
    #include <stdio.h>
    int main(void)
    {
        int num, product;
    
        for( num = 0; num<=10; num++ )
        {
            for( product = 0; product<=10; product++ )
                printf( "product of %d * %d is %d\n", product, num, product * num);
    
        }
        return 0;
    }
    ... and check the link in my signature for notes on how to use code tags.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    14

    Multiplication Code

    Thanks for your help -- but I need the mulitiplication table displayed in rows and columns.
    Anna

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: Multiplication Code

    Originally posted by Anna Lane
    Thanks for your help -- but I need the mulitiplication table displayed in rows and columns.
    ... then simply change the existing printf() statement to output something suitable for a row, and add putchar('\n'); at the end of the outer loop to start a new line.

    You'll have to do this yourself... no point in me doing it for you, I already know how to code and don't want to spoil your learning experience
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    Oct 2002
    Posts
    14

    Multiplication Code

    I'm new at this -- I've tried putting the rows and columns in printf but I continue to get errors; plus I'm not getting correct answers for my multiplication table. What am I doing wrong?
    Anna

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >What am I doing wrong?
    Post your code+errors, and someone will help you. Don't forget to use code tags when doing so.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    push
    Guest
    What am I doing wrong?
    You're not paying attention in class, or you didn't do your reading.

    Seriously, Hammer's right. If you give up this easily, you're never going to enjoy programming. It only gets more difficult.

  10. #10
    Registered User
    Join Date
    Oct 2002
    Posts
    14

    Multiplication Code

    //I need the multiplication table in rows and columns with answers. What's missing?

    Code:
    /*
    
    #include <stdio.h>
    
    int main()
    {
    	int num, product;
    
    	for( num = 0; num<=10;num++ ) {
    
    		for( product = 0; product<=10; product++)
    
    		
    	printf( "product of %d*%d is %d/n", product, num, product);
    	
    		
    	}
    
    	return 0;
    
    }
    
    */
    Anna

  11. #11
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Anna, Please don't start new threads with the same topic.

    The printf() call in your code doesn't quite match my version, I suggest you double check it. (its not doing any multiplication)

    I'll expand on what I said before about the loops:

    - the inner loop will printf() a rows worth of data, so you must remove the newline character in your current code.
    - on the outer loop, add a new statement to print out a newline character just after the inner loop has completed. The command for this would be putchar('\n');
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  2. matrix multiplication code
    By weneedhelp in forum C++ Programming
    Replies: 1
    Last Post: 04-11-2007, 06:50 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM