C If else Statement
Every Programming language provides structure for decision-making. C Language also provides these structures. These statements are known as C If else Statements. We divide this structure into two segments. If or Else, first we take if statement structure in C language.
if (Condition)
Statement (or group of statement)
The above statement express, if statement is true, then execute the group of statement or single statement. We can understand it from the example that Bill can become the member of the football team if he has a height more than 6 feet. In this case the condition will be
if (Bill height is greater than 6 feet)
Bill can be a member of a team
Here is the theory of block of statement.we use curly brackets { } to build a groups of statement. Before start a statement we put { and after write statement we put }. we enclosed the statement around two curly brackets { }. Let’s take an example to express the statement
#include // Header files using namespace std; main() { int Billmarks, Jhonmarks ; Billmarks = 20; Jhonmarks = 25; if(Billmarks < Jhonmarks) { cout<<"Jhon achieved the Goal"; } }
Above Example explicitly express the two students marks. And we determine between those marks and announced a winner one. You may use else statement if other condition applied. Here is different example.
#include // Header files using namespace std; main() { int Billmarks, Jhonmarks ; Billmarks = 20; Jhonmarks = 25; if(Billmarks < Jhonmarks) { cout<<"Jhon achieved the Goal"; } else // Else Statement Structure { cout<<"Bill Marks less than Jhon"; } }
Above example express the else statement structure. These if else structure utilize as decision structure means, if this statement is TRUE then RUN this statement otherwise run other one else statement.
FLOW CHART OF if else statement
Operator with if else statement
#include<iostream> // Header files using namespace std; main() { int a,b; cout<<"Enter value of a: "; cin>>a; cout<<"Enter value of b: "; cin>>b; if (a==b) { cout<<"Both are equal"; cin>>a; } else { cout<<"Both are not equal"; cin>>b; } }
Now Above example criteria is that we take two variables a and b & assign a specific values both of them. And next apply if else structure and inside of if condition we said if both values are equal each-other then display this string “Both are equal” otherwise execute other one else statement “Both are not equal”.Hope this article will help you, if you have any query feel free comment below.