+ 4
What does f*=i; really do in this code
#include <iostream> int main() { int f=1, i=2; while(++i<5) { f*=i; // what is this suposed to do ? } std::cout<<f<<std::endl; return 0; }
6 Réponses
+ 15
f *= i;
is similar to
f = f * i;
It assigns the product of f and i to f for each loop.
+ 10
Just leave it for future reference. :>
+ 6
Thank you i wasnt sure if that was the case for multiplications also.
Should i delete a question after im answered or leave it there ?
+ 3
it simply multiplies the variables f & i and stores the result in variable f.
f*=i means f=f*i
0
This was helpful.
also, I used http://cpp.sh/ to run the following. Interesting exponential jumps with this loop/function/expression:
/ Example program
using namespace std;
#include <fstream>
#include <iostream>
#include <string>
int main()
{
int f=1, i=2;
while(++i<12) {
f*=i;
cout<<f << endl;
}
}
Output:
3
12
60
360
2520
20160
181440
1814400
19958400