Not Yet Answered # Algo help

Sky Diploma 571 Discussion Starter prodigyaj Sky Diploma 571 Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

Well, Sum to n terms is

[tex] \frac{n*(n+1)}{2} [/tex]

Where is the need for [tex]a/b[/tex] in your equation.

Please Be a little more elaborate so that we can understand what exactly is your aim.

*Edited 7 Years Ago by Sky Diploma*: n/a

0

see i need to find the sum of i terms such that

sum = summation ( (a*i)/b )where a,b constant and i moves from 0 - 10^10

if this was the only question then you could solve it as

(a/b)=constant

then constant*(i+1)*(i)/2

but what I have to find is (int)(ai/b)

now saw a = 3 and b =2; and i is 0 - 4

so answer would be

3*0/2 + 3*1/2 + 3*2/2+3*3/2+3*4/2

=

0 + (int)1.5 + (int)3 + (int)4.5 + (int)6

=

0 + 1 + 3 + 4 + 6

=

14

I hope this should be clear now

Hoping for some help

Regards

AJ

0

From what i have understood from your question, You want to know what would happen if [tex]a/b[/tex] is a fractional value and not an integer.

Consider the following.

[TEX]Given a=3, b=2;[/TEX]

consider a variable

[Tex]val = a/b;[/tex]

If we have [tex]val[/tex] to be a type `int`

it would probably store 1.

This is because the integer data-type just excludes the decimal places. That way we donot need to worry that

[Tex] val * (\frac{ i *(i+1)}{2}) [/tex] when i =4 would be equal to

[tex] 1 * ( \frac{4*5}{2})[/tex]

Which would be equal to .

[tex] 1 * (10) [/tex]

which is equal to 10.

Which is a faulty answer. but if you consider val to be of type double, float.

it would be

[tex]1.5 * 10 = 15[/tex]

Which would be faulty as well,

This problem i think would be best solved with the help of a for loop and iterating. Continously.

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...