Describe if statement. Write an if statement to multiply even numbers by 3 and odd numbers by 4.
Answers
Answered by
5
if statement is a conditional statement in which the program performs an action if a particular condition is correct, else do another. This has two parts - the if block and the else block. General syntax is -
if(condition){
statements;
}
else{
statements;
}
if statement to multiply even numbers by 3 and odd numbers by 4 -
int n=2;
if((n%2)==0){//the % operator is to check the remainder
n=n+3;
}
else{
n=n+4;
}
Hope you understood what I told. :)
if(condition){
statements;
}
else{
statements;
}
if statement to multiply even numbers by 3 and odd numbers by 4 -
int n=2;
if((n%2)==0){//the % operator is to check the remainder
n=n+3;
}
else{
n=n+4;
}
Hope you understood what I told. :)
Similar questions