0

C++

Is it correct to write a%b is not equal to zero as !(a%b)==0 in while expression?? I wanna write a%b is not equal to 0...so how can i write this?

19th Nov 2019, 4:55 PM
Zainab Fatima
Zainab Fatima - avatar
4 odpowiedzi
+ 2
Can you describe what you are trying to do with the loop and such expression? !(a % b) == 0 May be evaluated different to (a % b) != 0 Elaborate some more on that please
19th Nov 2019, 5:09 PM
Ipang
+ 1
(a%b)!=0 != is a relational operator, meaning to "not equal to"... ! is a logical operator meaning to "not". if ! is applied, it converts true to false and vice versa. and zero from other than zero and vice versa. Both fine. choose according to your need..
19th Nov 2019, 5:09 PM
Jayakrishna 🇮🇳
+ 1
Zainab Fatima It is completely fine, but not many are used to it. For eg- #include <stdio.h> int main() { int n=10; int x=0; while(!(x==n)){ printf("hi\n"); x++; } return 0; }
19th Nov 2019, 5:18 PM
Avinesh
Avinesh - avatar
+ 1
(a%b)!=0
19th Nov 2019, 5:44 PM
Umair Khan
Umair Khan - avatar