[Solved] C error: lvalue required as left operand of assignment


1/h = 0 and (1/h) += (1/i) don’t work because you’re trying to assign a value the result of an expression, not an object. It’s like writing 1 = 2 and expecting it to be meaningful; it isn’t.

You’re trying to solve for h. So you need to sum 1/1 + 1/2 + 1/3 + ... and take the inverse:

double u = 0.0; // u == 1/h == 1/1 + 1/2 + 1/3 + 1/4 + ...

for ( int i = 1; i <= 1000; i++ )
{
  u += 1.0 / i;
}
printf( "1/h = %f, h = %f\n", u, 1.0/u );

0

solved C error: lvalue required as left operand of assignment