+ 1

Help me why this output ↓↓ ???

#include<stdio.h> #include<stdlib.h> int main(){ int x=9; x%=11; printf("%d",x); return 0; } //output:9 intead of 0

24th Feb 2022, 1:20 PM
Mik
Mik - avatar
2 Réponses
+ 4
Why 0? x%=9 means x = x%11= 9%11 = 9 See here https://www.sololearn.com/discuss/2988130/?ref=app
24th Feb 2022, 1:59 PM
Simba
Simba - avatar
+ 1
it works like this y=x%a; if (x<a) y=x; else y=x%a; example: y=3%4; //3<4 so y=3 y=4%3; // 4>3 so we get the reminder so y=1
24th Feb 2022, 2:30 PM
Aly Alsayed
Aly Alsayed - avatar