0
I am in doubt about the value of n in the code, in the "for" below 1 is assigned to the value of n, so it would not be for the first iteration the value of n to be 2?
#include <stdio.h>
int main(void){
float n=0;
int v=0;
for(n=1;n>=0 && v!=64;n=n+n){
v++;
printf("%i° Quad. tem %.0f grãos\n",v,n );
}
}
if assigned 1, how could it be 2 in the first interaction? that doesn’t make any sense
– Ricardo Pontual
in the sum n = n + n, n is worth 1 then the value would be 2 would not be?
– Saul44
As for "for", the block is only executed after the printf ? If so, it makes sense that n is worth 1 because it was displayed in the first iteration, it would be this?
– Saul44
The for command works as follows:
for (valor inicial; condição para continuar no loop; incremento)
in case theincremento
is executed at the end of the block, as if it were the last command. The condition is evaluated at each beginning of the block and the initial value only once. In fact, the traditional way of making such an increase in C would be:n*=2
.– anonimo
Thank you very much, my doubt has been resolved!
– Saul44