S = 1 + 2-1 + 2-2 + 2-3 + +2-2006, please calculate the formula on the right to get the value of S

S = 1 + 2-1 + 2-2 + 2-3 + +2-2006, please calculate the formula on the right to get the value of S


∵S=1+2-1+2-2+2-3+… +2-2006 ①,∴2S=S=2(1+2-1+2-2+2-3+… +2-2006)=2+1+2-1+2-2+2-3+… +2-2005 ②, ② - ①: S = 2-2-2006 = 2-122006 = 2 × 22006 − 122006 = 22007 − 122006



According to N, calculate the value of the following formula. S = 1 / 1 + 1 / 2 + 1 / 3 +. + 1 / N. for example, if you enter 5, you should output 2.28333
What's wrong? What's a good sentence to use?
Input everything is pop-up 1
int a = int.Parse (textBox1.Text);
int sum = 0;
int b = 0;
while ( a = 0)
{
b = b+1 / a;
sum = sum + b;
a = a - 1;
}
if(a==0)
MessageBox.Show ( sum.ToString ());
Just learned, do not understand these sentences, changed, or pop up 1


Sum is a decimal. If you define sum as an int, the result will be rounded automatically
Int sum = 0; change to double sum = 0; or float sum = 0
It's better to change a to floating point number as well
double a = double.Parse (textBox1.Text);
double sum = 0;
while ( a != 0)
{
sum = sum + 1/a;
a = a - 1;
}
if(a==0)
MessageBox.Show ( sum.ToString ());



In the formula s = 12 (a + b) h, it is known that s = 120, B = 18, H = 8


Substituting s = 120, B = 18, H = 8 into the formula s = 12 (a + b) h, we get: 120 = 12 (a + 18) × 8, the solution is: a = 12