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 - #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.                                      ...

C tutorial for complete beginners(intro to C language)

     A ny programming language has four important aspects viz * The way it stores data * The way it operates upon this data * The way it accomplishes input and output * The way lets u control the sequence of execution of program.  What is C?  C was developed by Ritchie in 1972 at AT and T's Bell laboratories, USA. Interestingly no one pushed it and there was no advertisement made but still programmers of the time preferred it over the older ones like FORTRAN. It was popular due to its simplicity, reliability and it's ease.  Inventor of C language,   Dennis Ritchie Why Still C in 2019?  As per today's opinion that C has been superseded by C++, C# and java one must still start his programming journey with C due to following reasons: 1. C++and C# use object oriented programming and basic programming skills         of C.  2. Mobile devices are today's rage and device like watches, ...

C tutorial #lecture 3

Here you will be introduced to the comments in C and some basic arithmetic operations on variables and you will learn various shorthand operators. Let's get started- Comments in C : Comments in C/C++ and in any other programming languages serve the purpose of improvement of readability of the code.  Comments are enclosed within /*-----------*/. This  symbol is used for multiline comments. For single line comments we use  // symbol  ( two backslashes) The rules of programming language aren't applicable within comments. The text doesn't appear in the output of the code but it appears in the source code. It just makes the program readable for the coder. This is a C code to illustrate comments.  Add caption       Output.  Nesting of comments : Comments written with /*----/*---*/--------*/  can't be nested and are invalid but a comment with  /*------//------*/ can be nested.  The f...