0
the code’s working as I need it, my doubt is why For didn’t go wrong? For example, if the exponent is 3, it will no longer be greater than 1 and then it would already stop the loop?
I was trying to make him for(expoente;expoente<=1;expoente--)
and it wasn’t working(this is the way I thought it would make sense). The code is below. It calculates power.
int main()
{
float pot,base;
int expoente;
scanf("%f", &base);
scanf("%d", &expoente);
pot=base;
for(expoente;expoente>1;expoente--)
{
pot=pot*base;
}
printf("%f", pot);
return 0;
}
It is always good to assign an initial value to the for control variable explicitly, for example: for (exponent=1; exponent<3; exponent++)
– anonimo