Multiplication Table using Array.

This is a discussion on Multiplication Table using Array. within the C Programming forums, part of the General Programming Boards category; Hi, so I'm writing a program that prints out multiplication table using two dimensional array. After i run it i ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    15

    Post Multiplication Table using Array.

    Hi, so I'm writing a program that prints out multiplication table using two dimensional array. After i run it i get errors, can some one assist me how to fix them?
    Thank you

    Code:
    #include <stdio.h>
    
    void multiply( int i, int j);
    
    int main(void)
    {
    int a;
    int i;
    int j;
    int answer;
    
    int a[ 13 ][13]=
    {{ 0,1,2,3,4,5,6,7,8,9,10,11,12},
    {  0,1,2,3,4,5,6,7,8,9,10,11,12}};
    
    multiply( i, j);
    answer = a;
    
    for ( int i = 0; i <= 13; i++)
    for ( int j = 0; j <= 13; j++)
    {
    a = a[i][j];
    printf("x 0 1 2 3 4 5 6 7 8 9 10 11 12");
    for ( i = 0; answer <= 26; i++)
    {
    printf("%-5d", a[i][j]);
    }
    }
    
    return 0;
    }
    
    void multiply( int i, int j )
    {
    int answer = 0;
    
    
    for( int i = 0; i <= 13; i++)
    {
    for( int c = 0; c <= 13; c++)
    {
    answer = i * c;
    
    }
    }
    Return answer;
    }

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You have multiply as a void return type, but include a return - you need to make up your mind what you want the compiler to do.

    Also, you're giving answer the value of a, but a is a constant pointer to the base of it's array, and answer is an int.

    You should go with multiply, and print from there. use i and c, and forget a[] completely - you don't need it. (Why is that?)

    What would happen if you printed up c x i equals answer, right in multiply?



    And *please* learn to indent. Reading "flat" code is a PITA.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 12:01 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. C++ Multiplication Table Generator
    By Visual Develope in forum C++ Programming
    Replies: 4
    Last Post: 05-15-2002, 11:22 AM

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