You are using a version without Ads of this website. Please, consider donating:

### c++ help

hi,,, i have one question about programing in c language:i must make the function which must calculate and retourn the sum of the members
"m" of type:1/(1*3)-1/(3*5)+1/(5*7)-...+-1/((2*m-1)*(2*m+1)). argument of function is value"m". can you do it or explain something, i do somethinglike this
#include <stdio.h>
#include <stdlib.h>
int vsota ()
{
{
int m;
int vsota;
for(1/((2*m-1)*(2*m+1)); m++)
vsota=1/(1*3)-1/(3*5)+1/(5*7);
return m;
}

system("PAUSE");
return 0;
}
i dont know what must i write for "for"........................please

Dividing a number by 1 isn't going to change anything.

maybe if you describe your project better and use format code tags <>

The for statement is not going to work the way it is.

you want something like
 ``1234`` ``````for (int m = 0; m < 99; m++) { // do your math here for m }``````

take out the `system("PAUSE"); `
it's damn ignoring

`int vsota ()` should be `int main()`
for should be something like this for (int b = 0;b<10;b++){code}

here b is zero then after; we have the condition for the loop to be true in this case so long as b is less than ten, lastly b++ increments b each loop

you need to explain what you are trying to do a little better i couldnt understand you, its not easy to communicate what your trying to do in code, it helps to use the <> button to create a couple of tags to stick your code between, comments on what your trying to do will also guarantee a snappier reply from a better coder :)
hi,,, i have one question about programing in c language:[b]i must make the function which must calculate and retourn the sum of the members
"m" of type:1/(1*3)-1/(3*5)+1/(5*7)-...+-1/((2*m-1)*(2*m+1)). argument of function is value
"m"[/b]. can you do it or explain something, i do somethinglike this
 ``1234567891011121314151617`` ``````#include #include int main () { int m; float vsota; for(m=0; m<99; m++) vsota=1/((2*m-1)*(2*m+1)); system("PAUSE"); return 0; }``````

i must write program in C language, must write the function, that function must calculate the sum and return that of first members of "m" .type:1/(1*3)-1/(3*5)+1/(5*7)-...+-1/((2*m-1)*(2*m+1)). argument of ffunction is "m"
The task is fairly straightforward. The requirement is to accumulate the total of a series.

Each term in the series is the reciprocal of the product of two consecutive odd numbers with an alternating plus or minus sign.

I'd tackle it step by step. First write a for loop to generate the series of odd numbers. When you have that, generating each term of the series is not too hard. And lastly add (or subtract) each term to the total.

can you give me some example or start to do this
i am begginer in this .... but....
This is a skeleton of the code, you'd need to enhance it to do the full job:

 ``123456789101112`` ``````double sum(int n) { // Need to find sum of the series // 1/(1*3) -1/(3*5) +1/(5*7) -...+-1/((2*m-1)*(2*m+1)) for (int m=1; m<=n; m++) { int odd1 = m*2 - 1; int odd2 = m*2 + 1; cout << "odd1: " << odd1 << " odd2: " << odd2 << endl; } }``````
Last edited on
 ``12345678910111213141516171819`` ``````#include #include int main () { int E; int F; int m; float vsota; for(m=0; m<99; m++) E = m*2 - 1; F = m*2 + 1; vsota = +-1/(E*F); system("PAUSE"); return 0; }``````

I DONT KNOW WHAT NEXT
Well, you lost some important things along the way.
Above, these two lines are the entirety of the `for` loop:
 ``111213`` ``````for(m=0; m<99; m++) E = m*2 - 1;``````

That's because you omitted the braces around the loop.

As to what you should do next , in all honesty I'd suggest practice with simple examples until you understand how your code works.

For example,let's say you want to find the sum of the numbers from 1 to 10.
1+2+3+4+5+6+7+8+9+10

But let's use a loop to do that.
 ``123456`` `````` int total = 0; for (int i=1; i<=10; i++) { total = total + i; } cout << "total = " << total << endl;``````

So now you know how to find the total of a very simple series.

In the real question, there are two other things to consider. Firstly, the terms involve fractional values, not integers, so you should use type `double` for the calculations. Secondly, the sign of each term alternates between plus and minus. It's no use just putting +- in there. The usual way to do this is to have a variable called sign. Set its initial value to +1. Each time around the loop, do this, `sign = -sign;` And multiply each term in the series by this value.

Hope this helps.

Last edited on
oo my friend ,,,, look this, if you can do it for me ,, i dont know ,, i must this work give to internet (my fax-school) to 00:00 h,,, if you can ,, if you donot ,, thank you enyway......
Topic archived. No new replies allowed.

You are using a version without Ads of this website. Please, consider donating: