Professional Documents
Culture Documents
C Chapter 3 LOOPs
C Chapter 3 LOOPs
3
TYPES OF LOOP:
There are two types of loop.
3
METHODS TO LOOP A PROGRAMME:
4
FOR LOOP OR FOR STATEMENT:
It is determinant loop.
5
The “FOR LOOP” specify
the following three statements:
A. INITIALIZATION: Means to assign value for
variable to initialize the loop. i.e (azr=11).
6
The above three operations are written in program as:
{
for (azr=11,azr<=20,azr=11+1)
expression update
initialization condition
{
Body of the loop
}
}
7
A program in for loop:
#include<stdio.h>
#include<conio.h>
void main ( )
{
int azr;
clrscr ( );
for(azr=5;azr<=45;azr=5+1)
{
printf(“%d\n”,azr);
}
getch();
}
8
To get even integers or odd integers:
if (azr%2==0);
}
if (azr%2!=0).
9
FOR EXAMPLE:
TO GET EVEN NUMBERS ON THE BLACK SCREEN:
#include<stdio.h>
#include<conio.h>
void main( )
{
int amb;
clrscr( );
{
for (amb=20;amb<=40;amb=amb+1)
if (amb%2==0);
}
printf (“%d\n”,amb);
getch();
}
10
TO GET ODD NUMBERS:
#include<stdio.h>
#include<conio.h>
void main( )
{
int X;
clrscr( );
{
for (X=9;X<=35;X=X+1)
if (X%2!=0);
}
printf (“%d\n”,X);
getch();
}
11