How to write an if statement with multiple || and && in C? [closed]
What is a concise way to write an if statement with more than many || and && in C?
I want to only execute a printf statement if a either 1,2,4 or 6 AND b = 8 and c = 10, can I put all these conditions into the same if statement?
eg. can I write something like:
if ((a = 1||2||4||6) && b == 8 && c == 10)
//do something
This doesn't seem to work...
c if-statement multiple-conditions
closed as too broad by devnull, dandan78, JJJ, A5C1D2H2I1M1N2O1R2T1, Blackhole May 18 '14 at 23:49
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
What is a concise way to write an if statement with more than many || and && in C?
I want to only execute a printf statement if a either 1,2,4 or 6 AND b = 8 and c = 10, can I put all these conditions into the same if statement?
eg. can I write something like:
if ((a = 1||2||4||6) && b == 8 && c == 10)
//do something
This doesn't seem to work...
c if-statement multiple-conditions
closed as too broad by devnull, dandan78, JJJ, A5C1D2H2I1M1N2O1R2T1, Blackhole May 18 '14 at 23:49
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
What is a concise way to write an if statement with more than many || and && in C?
I want to only execute a printf statement if a either 1,2,4 or 6 AND b = 8 and c = 10, can I put all these conditions into the same if statement?
eg. can I write something like:
if ((a = 1||2||4||6) && b == 8 && c == 10)
//do something
This doesn't seem to work...
c if-statement multiple-conditions
What is a concise way to write an if statement with more than many || and && in C?
I want to only execute a printf statement if a either 1,2,4 or 6 AND b = 8 and c = 10, can I put all these conditions into the same if statement?
eg. can I write something like:
if ((a = 1||2||4||6) && b == 8 && c == 10)
//do something
This doesn't seem to work...
c if-statement multiple-conditions
c if-statement multiple-conditions
edited Feb 2 '18 at 9:00
M.S Chaudhari
20.9k669137
20.9k669137
asked May 18 '14 at 8:17
user3649227user3649227
13112
13112
closed as too broad by devnull, dandan78, JJJ, A5C1D2H2I1M1N2O1R2T1, Blackhole May 18 '14 at 23:49
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as too broad by devnull, dandan78, JJJ, A5C1D2H2I1M1N2O1R2T1, Blackhole May 18 '14 at 23:49
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
if ((a == 1 || a == 2 || a == 4 || a == 6) && b == 8 && c == 10)
add a comment |
It might be better to write this with a switch
statement inside of an if
instead.
if(b == 8 && c == 10) {
switch(a) {
case 1:
case 2:
case 4:
case 6:
printf("value worksn");
}
}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
if ((a == 1 || a == 2 || a == 4 || a == 6) && b == 8 && c == 10)
add a comment |
if ((a == 1 || a == 2 || a == 4 || a == 6) && b == 8 && c == 10)
add a comment |
if ((a == 1 || a == 2 || a == 4 || a == 6) && b == 8 && c == 10)
if ((a == 1 || a == 2 || a == 4 || a == 6) && b == 8 && c == 10)
answered May 18 '14 at 8:20
Edward ClementsEdward Clements
4,54821524
4,54821524
add a comment |
add a comment |
It might be better to write this with a switch
statement inside of an if
instead.
if(b == 8 && c == 10) {
switch(a) {
case 1:
case 2:
case 4:
case 6:
printf("value worksn");
}
}
add a comment |
It might be better to write this with a switch
statement inside of an if
instead.
if(b == 8 && c == 10) {
switch(a) {
case 1:
case 2:
case 4:
case 6:
printf("value worksn");
}
}
add a comment |
It might be better to write this with a switch
statement inside of an if
instead.
if(b == 8 && c == 10) {
switch(a) {
case 1:
case 2:
case 4:
case 6:
printf("value worksn");
}
}
It might be better to write this with a switch
statement inside of an if
instead.
if(b == 8 && c == 10) {
switch(a) {
case 1:
case 2:
case 4:
case 6:
printf("value worksn");
}
}
answered May 18 '14 at 8:20
MakotoMakoto
81.5k17127176
81.5k17127176
add a comment |
add a comment |