Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to have the same condition for 2 variables in the same line?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading