C Programming - Lecture 5: if Statement
if Statement
We have seen that the computer can be one after another in a series. We need always to be executed one after another statement. We are also in a sartapurana sapekse If you want to execute one or more statements that we will use if statement.
Thus, if we write a statement
if ([Boolean expression])
{
[Code Block]
}
Example
Now let's see an example. We want to write a small program where one of a number of variables will score. And if this variable is more than 30, then we write the word PASS. If you are not more than 30 will not.
int score;
score = 35;
if (score> 30)
{
printf ( "PASS");
}
The [Code Block] we wrote a printf statement. This statement will work in our expressions score> 30 is set to True. False statement will not work if the value of expression.
Quiz 1
This will tell you whether or not to print anything on the console When you run the program must print and print tracked
int number;
number = 20;
if (number> = 15)
{
printf ( "% d", number);
}
Take a look at the video Quiz 1
Quiz II
We were assigned the number 0 instead of 13 variables can be printed to the console, then what?
int number;
number = 13;
if (number> = 15)
{
printf ( "% d", number);
}
Quiz Take a look at two of the uttarabhidiote
if else
We have seen how to use if an expression is True if you do something statements can be executed. Now, if we have an expression that is True and False Statements Some of the other things you want to execute the statement. So we will use if-else.
if ([Boolean expression])
{
[Code Block 1]
}
else
{
[Code Block 2]
}
Here [Boolean expression] True if the value of the [Code Block 1] will be executed when the False [Code Block 2] will be executed.
![]() |
| Example of if and else |
Example
Now let's see an example.
int score = 35;
if (score> 40)
{
printf ( "PASS");
}
else
{
printf ( "FAIL");
}
Boolean expressions to score> 40 will block the value of the False else, and so we will print FAIL.
Quiz 1
int num;
num = 30;
else
{
printf ( "B");
}
The program runs in the top of the console would say A, B, or not show anything.
Take a look at uttarabhidiote Quiz 1
Quiz II
Now we have a little change at the top programataya write num = 20. Now, what would be balathe.
int num;
num = 20;
else
{
printf ( "B");
}
Quiz Take a look at two of the uttarabhidiote.

No comments: