- #1
loli12
I am learning how to use the for loop to find out the total of:
1/30 + 2/29 + 3/28 + ... + 29/2 + 30/1
and i wrote the following. but it doesn't work and give the correct total.
can you guys tell me what's wrong?
Thanks
#include <iostream>
using namespace std;
int main ()
{
int num, den; //numerator, denominator
double total=0;
for (num = 1, den = 30; num < 31; num++, den--)
total += (num/den);
cout << "Total is " << total<< endl;
return 0;
}
1/30 + 2/29 + 3/28 + ... + 29/2 + 30/1
and i wrote the following. but it doesn't work and give the correct total.
can you guys tell me what's wrong?
Thanks
#include <iostream>
using namespace std;
int main ()
{
int num, den; //numerator, denominator
double total=0;
for (num = 1, den = 30; num < 31; num++, den--)
total += (num/den);
cout << "Total is " << total<< endl;
return 0;
}