Thread: Simple multiplication via arrays

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    14

    Simple multiplication via arrays

    Hello all, my latest assignment was to find the sum of 2 numbers using functions which I managed to do. I decided to try and get the multiplication tables of x up to 12 using functions. I get the error code: "undefined reference to xyz". XYZ is just a random name for the function. Any help would be greatly appreciated, thank you.

    Code:
     #include<stdio.h>#include<stdlib.h>
    int xyz(int x);
    int main()
    {
        int x,i;
        printf("Enter the number for which you want a multipication table for: ");
        scanf("%d",&x);
        for (i=0;i<x;i++)
        {
            printf("%d*%d=%d",x,i,xyz(x));
        }
        int xyz(int x)
        {
            return x*i;
        }
    }

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Functions aren't defined inside of other functions.

    See Functions in C - Cprogramming.com for the proper method.

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    You cannot define a function within another function as you have with xyz inside main (OK, GCC allows this, but it's a non-standard extension).

  4. #4
    Registered User
    Join Date
    Jul 2012
    Posts
    14
    Ah I completely forgot to end the main, thank you very much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple arrays
    By DerrickakaDRoC in forum C Programming
    Replies: 12
    Last Post: 12-12-2010, 10:57 PM
  2. Simple Multiplication Function.
    By admin in forum C Programming
    Replies: 3
    Last Post: 10-04-2010, 01:49 PM
  3. Doing multiplication using numbers in arrays
    By neandrake in forum C++ Programming
    Replies: 17
    Last Post: 11-05-2004, 11:07 AM
  4. Matrix Multiplication with simple syntax! plz help.
    By codebox in forum C Programming
    Replies: 6
    Last Post: 11-05-2004, 09:03 AM
  5. Matrix multiplication using 1-d arrays
    By Befuddled in forum C++ Programming
    Replies: 2
    Last Post: 05-25-2003, 09:35 PM