Enter your email id to get regular update free
Login
Your Email
Pasword

Branching in #C : concept of If and their uses in programs (part 1) (module-19)

In this section we will discuss on the important topic of C. The control statements and its many applications in writing a program using the concepts of loops and branching. Different types of branching like if statement, if-else statements, nested if else statements etc.

This is the 19th module on learning C with us. Earlier we discussed on the basic introduction and structure of C, preprocessor it's features, intermediate and executable codes. compilation and execution process of a C program. And keywords and identifiers, data types, variables and constants, scope of variables, operators and expressions in C. Type casting in #C. Introduction to input and output functions and reading a character in #C. Unformatted and formatted input functions.
In this section we will discuss on the most important topic of C that is branching. different types of branching like if statement, if-else statements, nested if else statements etc.
Branching :-
They decide the flow of statements based on evaluation of results of condition. There are many types of branching statement :
1. If satements.
2. If-else statements.
3. Nested If-else statements.

If statement :-
format :     if(condition)
                    {    statement 1;
                          statement 2;   }
The keyword if tells the compiler that what follows is a decision control instruction. The condition following the keyword IF is always enclosed within pair of parentheses. If the condition is true then the statements executed otherwise statements is not executed.

Example :
 1.
                  main()
                  { int a,b;
                     printf("enter two values");
                     scanf("%d%d",&a,&b);
                     if(a>b)
                                printf(" a is greatest");
                     if (a<b)
                                printf(" b is greatest");
                     }
 2.
                   main() 
                   { int x, y=9;
                      x=y+2;
                      y=x%2;
                    If (x>y)
                         Printf("%d is x",x);
                   If (y>x)
                        Printf("%d is y",y);
                  }
In next module we will continue our discussions on the next topic on if else and nested if-else structure. For more information regarding #C please be updated with us only on Www.newsandstory.com as we provide all the information on all the topics covered in #C.
  For part-2 and part-3 on if else and nested if-else please refer here :
Part 2 ( if-else)
Part 3 (nested if-else)
control statements
if
if-else
nested if-else
branching
looping
#C
programming
learning
coding
Dalpat I
Content writer
Total 75 views