![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2005
Posts: 3
Rep Power: 0
![]() |
calculating phi. problem
#include <cstdlib>
#include <iostream>
#include <stdint.h>
#include <io.h>
#include <math.h>
int main()
{
double phi = 5;
for (long int n = 0; n < 5000; n=n+1)
{
phi=(1/phi)+1;
}
printf("Estimated PHI value: %f "),phi;
scanf("press enter: %d");
return 0;
}i want this to return a value which is approximately phi (1.618033989...) but it just gives me "Estimated PHI value: 0.00000000" any help would be appreciated |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
You have the printf statement messed up - phi is outside the brackets. You should have:
printf("Estimated PHI value: %f ", phi); |
|
|
|
|
|
#3 |
|
Programmer
|
You've got the variable outside the printf statement...
try: printf("Estimated PHI value:%f ", phi);
__________________
~ You know, Hobbes, some days even my lucky rocketship underpants don't help. ~ read my blog @ My Lucky Rocketship Underpants
|
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Beat ya to it. :p
|
|
|
|
|
|
#5 |
|
Programmer
|
Ooble - by seconds =^)
Tomm - is that code part of a larger program? If not, you don't need most/all of those include statements...and I'm surprised that printf works without stdio.h (although I'm not sure what's in some of those libraries so it might be in there as well)
__________________
~ You know, Hobbes, some days even my lucky rocketship underpants don't help. ~ read my blog @ My Lucky Rocketship Underpants
|
|
|
|
|
|
#6 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
I believe it's in io.h as well.
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Jan 2005
Posts: 3
Rep Power: 0
![]() |
i hope to expand this program to calculate many significant figures of phi, which is the solution to the equation x*x-x-1=0.
i'm not really an experienced programmer so i just learned from online tutorials and such so i don't really know what those include things are, etc. |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Feb 2005
Posts: 2
Rep Power: 0
![]() |
#include<iostream.h>
#include<stdio.h> #include<conio.h> void main() { double phi =5; for( long int n=0;n<5000;n++) //n++ is same as n=n+1; { phi=(1/phi)+1 } cout<<"estimated phi values is : "<<phi; \\printf("estimated phi value is :%f",phi); getch();\\to make wait } |
|
|
|
|
|
#9 | |
|
Newbie
Join Date: Feb 2005
Posts: 2
Rep Power: 0
![]() |
PHI - the Golden Ratio
// Phi, the Golden ratio
// We can calculate Phi without recursion or iteration, // as it is one solution to a quadratic equation. // phi = 1/2 = 1/2 *(SQRT(5)). double PHI = 0.5 +pow(5.0,0.5)/2.0; // print out in the normal manner // Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|