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?
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
+ 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..
+ 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;
}
+ 1
(a%b)!=0