please...me/Im a beginner

how can i calculate
(1/25)+(3/24)+(5/23)+(7/22)+(9/21)+(11/20)
using two (for loop)
the answer is=1.6791
Last edited on
try this:
1
2
3
4
5
double s = 0;
for(int i = 0;i <= 5;i++)
{
     s += (1 + 2 * i) / (25 - i);
}

Above will not work unless you want zero. You'll need to do
this in the floating point domain. But I don't know why you'd
need two loops.
hi,it looks correct,but it doesn't work;
could you try it?
thanks very much...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<iostream>
using namespace std;

int main()
{
	float a=1, b=25, total=0, sum=0;
	int count=0;

	while(count <= 5)
	{
		for(int i=0; i<5; i++)
		{
			for(int j=i; j<1; j++)
			{
				sum = a/b;
				cout<<a<<"/"<<b<<" = "<<sum<<endl;
				total = total + sum;
				a+=2;
				b--;
			}
		}
		count++;
	}
	cout<<"\nThe Total is"<<" = "<<total<<endl<<endl;
	return 0;
}


Hope this will help you
as an aswer to jsmith:because my teacher has said...(laughing)
--------------------------------------------------------------------------------------
bello...
thank you very very very much...
it works nice and perfect...kissss kiss kisssss

Hope this will help you


It will help him cheat on his schoolwork. Too bad it won't help him actually learn anything.
I just want to tell you the aglorithm before.

1
2
3
4
5
double s = 0;
for(int i = 0;i <= 5;i++)
{
     s += (double)(1 + 2 * i) / (25 - i);
}
Last edited on
Topic archived. No new replies allowed.