| | |
series of 1 + 1/2 + 1/3 ...etc
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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?
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?
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets







