| | |
series of 1 + 1/2 + 1/3 ...etc
![]() |
The first step to figuring out how to write the program is figuring out how to write the algorithm. How would you solve this problem with pencil and paper? Where would you start? What steps would you take?
Dani the Computer Science Gal 
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds

Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
u need an array
float x[20];
// to enter the codes now.use a for loop
int i,y=1;
for (i=0;i<20,i++)
x[i]=1/y+1/y+1;
// to calculate total
for(i=0;i<20;i++)
total=x[i]+x[i+1];
if (total>5) num=x[i]// declare num first somewhere in the program
// how many terms needed
of course this is not the absolute code but i guess you are intellighent enough to go ahead
before writing any program do it on paper first
get the logic first then use your computer
:lol:
float x[20];
// to enter the codes now.use a for loop
int i,y=1;
for (i=0;i<20,i++)
x[i]=1/y+1/y+1;
// to calculate total
for(i=0;i<20;i++)
total=x[i]+x[i+1];
if (total>5) num=x[i]// declare num first somewhere in the program
// how many terms needed
of course this is not the absolute code but i guess you are intellighent enough to go ahead
before writing any program do it on paper first
get the logic first then use your computer
:lol:
:lol: I am not one of those who wait for things to happen, :p but one of those who make things happen ;)
•
•
•
•
Originally Posted by anastacia
well dave please clarify the reason. coz i am not an expert in c++. thanks in advance
Or the integer math? In integer math, 1 / 2 = 0. But floating point math, 1.0 / 2 = 0.5. If you take the integer result 0 and (implicitly) convert to floating point, you will have 0.0. You can see how this would seriously affect the calculation.
•
•
•
•
Originally Posted by anastacia
yeah sort of understanding a little bit. jwenting said something about a counter can you please clarify that ... point.
thnx in advance
This is hard not to completely give away since it's only about 4 lines of code -- why not post an attempt?
![]() |
Similar Threads
- HP 1900 Series (Cellphones, PDAs and Handheld Devices)
- ATI Radeon x series question? (Motherboards, CPUs and RAM)
- Sony PCV-RX series power supplies (Troubleshooting Dead Machines)
- sum of series (C++)
- Rename a Series of Files (Windows tips 'n' tweaks)
- HP Laserjet 1000 Series (USB Devices and other Peripherals)
Other Threads in the C++ Forum
- Previous Thread: how to read file names from a folder
- Next Thread: iostream in C?
Views: 3001 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for C++
6 algorithm array arrays assignment beginner binary browser c++ c/c++ calculator char class classes code compile compiler constructor conversion convert count delete dll dynamic encryption error file files filestream fstream function functions game givemetehcodez graph gui homework i/o iamthwee input int lazy library link linker list loop loops map math matrix member memory newbie number object objects opengl operator output parameter path pointer pointers problem program programming project random read recursion recursive reference server sockets sort spoonfeeding string strings struct student studio template templates text time tree undefined url variable vc++ vector video visual win32 window windows winsock wordfrequency wxwidgets






