Decision Control in C
Hello friends,
We read about the logical operator in a previous post. Today we will study new topic which is 'decision control in c language' in very detailed.
Then first, we have to know about 'What is control in c language '
What is 'control' in c language?
In c language, we write its main body in this way which is given below
#include<stdio.h>
#include<conio.h>
void main()
{
Instruction 1;
Instruction 2;
Instruction 3;
Instruction 4;
}
here, I write 4 Instruction. When the program runs, all the instructions are executed one by one.Our processor control all these instructions.
When first instruction is executed then we can say that the processor control the first instruction.
The processor control all instruction in sequence order not random order .
If we want to run first instruction and then fourth instruction for this we study control instruction
what is control instruction?
There are four type of control instruction
1. Decision control instruction
2. Iterative control instruction
3. switch case control instruction
4. goto control instruction
Then first we will study about 'Decision control instruction'
Decision control instruction
It is also called selection control instruction'
There are three ways to implement this in c language.
1. If
2. If-else
3. conditional operator(?:)
First we will study about'If' Statements in this post.
If Statements
for example
Output
pass
fail
We have written four instruction here and it will run in sequence
Now we want that the 'fail' instruction is not executed, how will we do it? And also we have a question is if we do not want to run 'fail' instruction, then why should we write this instruction?
But there are some instructions which are in the program but we have to execute the instruction only in some specific condition.
For example
Look at the syntax given above, if the code is written inside parentheses () followed by curly braces {}, which will execute when the condition is true.
Output
pass because we know that 33 is less then 34 and the above condition is false so it does not execute.
Now, If we want to know the number is positive or negative then we follow this code which is mentioned below
Output
if we enter any number less then 0 then it show no positive number otherwise it show positive number
Also read
Thanks for reading
0 Comments
Please do not enter any spam link in the comment box and please follo me.