| Thread Closed |
Programing C |
Share Thread |
| Mar7-06, 03:32 PM | #1 |
|
|
Programing C
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! |
| Mar7-06, 03:58 PM | #2 |
|
|
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 |
| Mar12-06, 03:41 AM | #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! |
| Mar12-06, 08:00 AM | #4 |
|
|
Programing C
Is %fl allowed in C at all? I know %f is.
|
| Mar12-06, 11:53 AM | #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) |
| Mar12-06, 11:57 AM | #6 |
|
|
I thought it was %lf, not %fl.
Anyways, did you remember to link your program with the math library, when you compiled it? |
| Mar15-06, 02:04 AM | #7 |
|
|
If you change your scanf and your printf statements to this
Code:
...
scanf("%lf",&x);
...
printf("%lf", y);
...
|
| Thread Closed |
Similar discussions for: Programing C
|
||||
| Thread | Forum | Replies | ||
| What is the best way to learn Windows programing? | Programming & Comp Sci | 5 | ||
| *****need help programing in assembly language***** | Programming & Comp Sci | 1 | ||
| Is Intro to Java difficult without programing experience? | Academic Guidance | 8 | ||
| Help~~An asighment about Matlab programing! | Math & Science Software | 2 | ||