0
Hii frnds how is this code working could somebody help me ??
#include <iostream> using namespace std; int main() { int m; for(m=0;m<3;m++){ cout << ((m%2)?m:m+2); cout <<" "; } return 0; } //output---> 2 1 4
4 Antworten
+ 2
at the beginning of for loop m is 0.
so program checks is 0 % 2 one or zero if one (so, true) then write just m (which is zero for now), if not then plus 2 to m (now m is 2) then print it.
condition ? something1 : something2;
if condition is right something1 is executed, if wrong something2 is executed.
+ 2
https://code.sololearn.com/cnrK1VhSmyeP/?ref=app
this versiin of your code should give you some insights about what is going on:
the for loop runs 3 times
and each time the value of m increases by 1.
the output inline if statement returns m if the reminder of m/2 is 1 else m+2 if the reminder is 0
(m%2)? m : m+2;
(m%2)? evaluate the reminder of m/2
return m if it is true/1
: else
return m+2 (if is false/0)
0
thankew @Mistafa K. i got it how this actually works
0
thanks all of u