Why does this code output this number (it should be different)

1
2
3
4
5
6
7
8
9
float i,m,n;
float newsum=0;
    for (i=1;i<=10;i++)
        for (m=1;m<=10;m++)
            for (n=1;n<=10;n++)
                if (i<m<n) {
                    newsum=newsum+(m*n*i)/(i*m+m*n+n*i);
                    cout << newsum << endl;
                }


The very first number that is shown in the launched program is
0.33333
although shouldn't it be
0.5454
since
(1*2*3)/(1*2+2*3+3*1)=6/11
?

It looks like the first triplet of numbers that satisfies the 'if' condition should be
(1,2,3)
, but the output doesn't agree with me..
Last edited on
Line 6 makes no sense. I'd guess that you mean if (i<m && m<n) {

Maybe you want this

1
2
3
    for (i=1;i<=10;i++)
        for (m=i + 1;m<=10;m++)
            for (n=m + 1;n<=10;n++)


Without the if?
wow, great idea coder777.
Topic archived. No new replies allowed.