Sample


[br]4 [br]In C you can use <strong>conditional statements</strong> to <strong>execute a piece of code only when a logic expression is true</strong>. <code>if(<i>expression</i>) {<i>code</i>}</code> is the <strong>main</strong> conditional statement. The code between curly brackets is executed only if the expression is <strong>true</strong> - <em>that in C means it's different from 0</em>. <code>else if(<i>expression</i>) {<i>code</i>}</code> is a conditional statement that can be only used <strong>after an if or another else if</strong>. It's <strong>cosidered</strong> when the conditional statement before it is <strong>false</strong>, otherwise it's <strong>ignored</strong>. <code>else {<i>code</i>}</code> can be used only <strong>after an if or else if</strong>. Its code is executed when the previous statements (if not ignored) are <strong>all false</strong>. [crayon-5daf71ed6f58b227131405/] The link below contains a <strong>list of all logic operators</strong> with their description. [br]https://itszephyro.com/blog/learn-c/conditions/[br]#include <stdio.h> int main() { int var; printf("Enter a number: "); scanf("%d", &var); //A % B = remainder of an integer division between A and B if(var%2==0) { printf("%d is an even number", var); }else{ printf("%d is an odd number", var); } } [br]

[br]4
[br]In C you can use conditional statements to execute a piece of code only when a logic expression is true.

if(expression) {code} is the main conditional statement. The code between curly brackets is executed only if the expression is truethat in C means it’s different from 0.

else if(expression) {code} is a conditional statement that can be only used after an if or another else if. It’s cosidered when the conditional statement before it is false, otherwise it’s ignored.

else {code} can be used only after an if or else if. Its code is executed when the previous statements (if not ignored) are all false.

The link below contains a list of all logic operators with their description.
[br]https://itszephyro.com/blog/learn-c/conditions/[br]#include

int main() {
int var;
printf(“Enter a number: “);
scanf(“%d”, &var);
//A % B = remainder of an integer division between A and B
if(var%2==0) {
printf(“%d is an even number”, var);
}else{
printf(“%d is an odd number”, var);
}
}
[br]

To learn more, visit: