Posts

do-while in C

Image
do-while in C A  do-while  loop is similar to a  while  loop, except that a do-while loop is execute at least one time. A  do while  loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given condition at the end of the block (in while). Syntax do { Statements ; ........ Increment or Decrements (++ or --) } while ( condition ); Flow Diagram When use do..while loop when we need to repeat the statement block  at least one time  then use do-while loop. In do-while loop post-checking process will be occur, that is after execution of the statement block condition part will be executed. In below example you can see in this program i=20 and we check condition i is less than 10, that means condition is false but do..while loop execute once and print Hello world ! at one time. Example of do..while loop #include <stdio.h> #include <conio.h> void main () { i

For Loop in C

Image
For Loop in C When you need to execute a block of code several number of times then you need to use looping concept in C language. In C Programming Language  for loop  is a statement which allows code to be repeatedly executed. It contains 3 parts. Initialization Condition Increment or Decrements Syntax for ( initialization; condition; increment ) { statement(s); } Initialization:  This step is execute first and this is execute only once when we are entering into the loop first time. This step is allow to declare and initialize any loop control variables. Condition:  This is next step after initialization step, if it is true, the body of the loop is executed, if it is false then the body of the loop does not execute and flow of control goes outside of the for loop. Increment or Decrements:  After completion of Initialization and Condition steps loop body code is executed and then Increment or Decrements steps is execute. This statement allows to update any loop cont

While Loop in C

Image
While Loop in C In  while loop  First check the condition if condition is true then control goes inside the loop body other wise goes outside the body.  while loop  will be repeats in clock wise direction. Syntax Assignment; while(condition) { statements; ............ Increment or Decrements (++ or --); } Note:  If while loop condition never false then loop become infinite loop. When while loop is use ? When we do not know about how many times loops are perform or iteration of loop is unknown. Flow Diagram Example of while Loop #include <stdio.h> #include <conio.h> void main () { int i ; clrscr (); i = 1 ; while ( i < 5 ) { printf ( "\n%d" , i ); i ++; } getch (); } Output Output: 1 2 3 4 Execution process of  while loop  is slower than  for loop . Next

Looping statement

Image
Looping statement Looping statement  are the statements execute one or more statement repeatedly several number of times. In C programming language there are three types of loops; while, for and do-while. Why use loop ? When you need to execute a block of code several number of times then you need to use looping concept in C language. Advantage with looping statement Reduce length of Code Take less memory space. Burden on the developer is reducing. Time consuming process to execute the program is reduced. Types of Loops. There are three type of Loops available in 'C' programming language. while loop for loop do..while Difference between conditional and looping statement Conditional statement executes only once in the program where as looping statements executes repeatedly several number of time. While loop In  while loop  First check the condition if condition is true then control goes inside the loop body other wise goes outside the body.  whi

Operators In ''C' Language

An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators − Arithmetic Operators Relational Operators Logical Operators Bitwise Operators Assignment Operators Misc Operators We will, in this chapter, look into the way each operator works. Arithmetic Operators The following table shows all the arithmetic operators supported by the C language. Assume variable  A  holds 10 and variable  B  holds 20 then − Show Examples Operator Description Example + Adds two operands. A + B = 30 − Subtracts second operand from the first. A − B = -10 * Multiplies both operands. A * B = 200 / Divides numerator by de-numerator. B / A = 2 % Modulus Operator and remainder of after an integer division. B % A = 0 ++ Increment operator increases the integer value by one. A++ = 11 -- Decrement operator decreases the integer value by one. A-- = 9 Relationa