Simple multiplication via arrays

This is a discussion on Simple multiplication via arrays within the C Programming forums, part of the General Programming Boards category; Hello all, my latest assignment was to find the sum of 2 numbers using functions which I managed to do. ...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,666
    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
    383
    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, 09: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, 10:07 AM
  4. Matrix Multiplication with simple syntax! plz help.
    By codebox in forum C Programming
    Replies: 6
    Last Post: 11-05-2004, 08: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

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