Fractions: Sum and difference in C programming
<p>I'm facing problems in writing a program in C that calculates S, being S = {1/50 - 3/48 + 5/46...} with 9 elements. I don't know how to use the DIFFERENCE operator followed by a SUM operator, and I MUST use the <strong>for</strong> structure. </p>

<p>Here's the program I wrote:</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

int main (void) {
    int n, d, S, i;
    i = 0;
    n = 1;
    d = 50;
    S = n / ((double)d);

    for (i = 0; i &lt; 4; i++) {
        n += 2;
        n -= 2;
        S = S + (n / ((double)d));
        S = S - (n / ((double)d));
    }
    printf("%d", S);
    return 0;
}
</code></pre>

<p>I know that the variable declarations may be wrong and that's exactly where I get confused. I decalred S as an integer but put d (denominator) to double 'cause the result must be a decimal number, of course.</p>

<p>Can anybody help me??</p>

<p>The output I'm getting is: <code>0</code></p>