Thread: Calling functions

  1. #1
    Registered User
    Join Date
    Mar 2008

    Calling functions

    I am attempting to write a program that calls a function, finding all prime numbers from 1-1000. My code is as follows, but I can not get it to run. Any suggestions?

    #include <stdio.h>
    int prime(x);
       int i,d;
       d=prime(int x);
    int prime(int x)
    { int temp=x;
      {return 0;
       else if(temp%i!=0);
       {return 1;

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    First suggestion: Tell us what "can not get it to run" means. How about giving us the compiler errors or something else to go on?

    Here are the list of errors my compiler is complaining about:

    :2: warning: parameter names (without types) in function declaration
    :4: warning: return type defaults to `int'
    : In function `main':
    :7: error: syntax error before "int"
    : In function `prime':
    :13: error: `i' undeclared (first use in this function)
    :13: error: (Each undeclared identifier is reported only once
    :13: error: for each function it appears in.)
    :15: error: syntax error before "else"
    Fix these.

    And btw, next time the C programming section would be better to place this type of post.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Moved to C board.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 04-12-2009, 05:49 PM
  2. Replies: 9
    Last Post: 01-26-2008, 03:12 AM
  3. calling functions: exit and return
    By 911help in forum C Programming
    Replies: 3
    Last Post: 12-28-2007, 01:24 PM
  4. I Need Help Defining and Calling Functions
    By jonbuckets in forum C++ Programming
    Replies: 6
    Last Post: 10-25-2007, 09:46 AM
  5. Calling functions help
    By ForlornOdium in forum C++ Programming
    Replies: 14
    Last Post: 09-29-2003, 08:40 PM