Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Programing C

  1. Mar 7, 2006 #1
    I wrote the following "program"

    #include <stdio.h>
    #include <math.h>


    int main()
    {
    double x,y;

    printf("enter a number");
    scanf("%FL,&x_one");


    y = pow(x,3.0) - 4.0*x + 1.0;
    printf("%d",y);

    return 0;

    }

    could anyone tell me why I can't get a correct result from this?
    What had I done wrong with the pow(power) operation?
    THANX!
     
  2. jcsd
  3. Mar 7, 2006 #2

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    The line

    scanf("%FL,&x_one");

    doesn't make any sense. Did you put the quote marks in the wrong place? Did you mean:

    scanf("%FL", &x_one);

    Of course, the variable x_one doesn't exist in your program, and you probably should use lowercase characters in your scanf -- like "%fl".

    - Warren
     
  4. Mar 12, 2006 #3
    even I corrected the errors you pointed out to me...

    i can't get any other result but the degit "0"!
    I use miracle C to compile it.

    corrected program:
    #include <stdio.h>
    #include <math.h>


    int main()
    {
    double x,y;

    printf("enter a number");
    scanf("%fl",&x);


    y = pow(x,3.0) - 4.0*x + 1.0;
    printf("%d",y);

    return 0;

    }

    I think the "pow" function is not being recognized...
    whatever vulue I enter in the parathesis after pow function, it returns 1!
     
    Last edited: Mar 12, 2006
  5. Mar 12, 2006 #4
    Is %fl allowed in C at all? I know %f is.
     
  6. Mar 12, 2006 #5
    my text book said yes, its a must in a scanf() thing

    the thing is the program works fine when its

    y = x*3.0) - 4.0*x + 1.0
    or y = x-3.0 - 4.0*x + 1.0
    or whatever other thing I tried

    just not pow(x,3.0)
     
  7. Mar 12, 2006 #6

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    I thought it was %lf, not %fl.

    Anyways, did you remember to link your program with the math library, when you compiled it?
     
  8. Mar 15, 2006 #7
    If you change your scanf and your printf statements to this
    Code (Text):
    ...
    scanf("%lf",&x);
    ...
    printf("%lf", y);
    ...
    it should work (I tried it, and it works fine)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Programing C
  1. C program (Replies: 4)

  2. C program (Replies: 4)

  3. C Program (Replies: 3)

  4. C program (Replies: 0)

  5. C programming (Replies: 9)

Loading...