I have this condition if (n >= 1) && (n <= 10^4)
and I would like to know how can I have the same condition for another variable in the same line, instead of being for n
being to n
and m
(for example).
I tried to add the n
and anotherVariable
but I couldn't figure out how to do it without giving me bugs.
CodePudding user response:
You can have as many as you require:
if ((n >= 1) && (n <= 10^4) && (condition))
NB that the &&
operator short-circuits. If the first expression is false
, the rest of the expressions shall not be evaluated and the if
block shall not be entered.
The braces around the expressions are not necessary, but improves readability.
Also not that the ^
operator is the bitwise exclusive-or operator in C
.
C
does not have a built-in operator for exponentiation, but the standard library provides some functions for it.
#include <math.h>
double pow(double x, double y);
float powf(float x, float y);
long double powl(long double x, long double y);