Skip to main content

Control structures in c #part 1 ( if statement)

The control strucures are the statements that are used to alter the flow or sequence of excecution of program. 

There are basically two types of control strucures:

                  1. Decision making statements

a) if statement
         b) if -else statement
         c) switch statement

2. Loop constructs:

a) for loop
    b) while loop
          c) do-while loop

We will also study about break, continue and go to in subsequent lectures
Here we will cover if statement. 


Firatly u need to know the symbols for various conditions they are called relational operators. 

1. ==  means here "equal to "
2. <= means here "less than Or equal to"
3. >= means here "greater than Or equal to"
4.  ! = means " Not equal to"

Now u are euipped  enough to learn loops. 

Let's begin with the if statement

 If statement:

The if statement is used to excecute the code if certain condition is true. 

General from of if statement is 

If(condition) 
{
Statements
}

The flow chart of if else statement is as follows

If the condition is false then the program simply runs after skipping the if statement. 

Let's take a simple code to check if the number is divisible by 10.

Source code.

The statement is not printed which means that our input no. Is not divisible by 10.
So the condition is false.

Now let's see what's the output if the condition is true.

     


Let's see the output.

The condition is true so the statement got printed.

Conclusions:

Uve learnt about the working of if statement and are ready to use it.

Did u find it interesting?


Comments

Popular posts from this blog

Python tutorial - #3 (Docstrings and Data-Type)

Docstrings = If we write string inside triple single quote (‘’’----‘’’) or triple double quote (“””----“””) and if these strings are written as first statements in a module, function, class or a method. Then these strings are called Documentation strings or simply Docstrings. These strings are useful to create an A.P.I documentation file from python program, An A.P.I (Application Programming Interface) documentation file is a text file or HTML file that contains the description of all features of software or product. When software is created it is the duty of programmer to create docstrings file in which they explain each and every class, Module, function etc. properly. It helps the user of the product (software) to use this smoothly. Representing Binary, Octal and Hexadecimal number. ➠In python, Binary number are represented by adding 0 (zero) B or 0 (zero) b as prefix to each binary number. Example: - 0B11001, 0b00101 etc.       ...

#lecture 2 coding of your First C program

Structure of a C program: #include<header file> Int main()  { ----; ---; ---; } The # sign tells the compiler to include the header file(generally iostream) Header file is included as it is the standard library of all readymade C commands that are fed to the compiler. " Iostream " stands for input output library and has various commands like cin>>, cout<<, basic arithmetic operations.  The main() is very crucial in C. The Main() is a C function and just like a calculator returns a value, the main function returns integer value. So we write int before main. The compilers like turbo C/C++ even allow us yo return no value from main function i.e. void So we sometimes write void main().  The sequence of commands that the compiler has to follow are written between the curly brackets.  The statement in C are ended with ' ; ' Before writing your first C program u need to equip with these things first!   Data t...

Python tutorial - #5 (Operators in Python)

Membership Operators This operator helps us to check an element is found in a sequence or not. It gives there result in Boolean value (True or False). ➥There are two types of Membership operator :- a) in b) not in ➢in membership operator This membership operator returns True if an element is found in a sequence and it returns  False When an element is not found in a sequence. Program - #1 ➢not in membership operator This membership operator returns True if an element is not found in a sequence and it returns False if an element is found in a sequence. Program = #2 Identity Operators This operator helps us to check whether two element are same or not. Actually, this operator compares the memory location of two object, if the memory locations are same then objects are also same otherwise the objects are not same.                                      ...