For loop in C

Spread the love

For Loop in C:

Example 1:

#include<stdio.h>
#include<conio.h>
void main()
{
int a;
for(a=0;a<=10;a++)
{
printf("a= %d\t",a);
}
getch();
clrscr();
}

Output:

a=0 a=1 a=2 a=3 a=4 a=5 a=6 a=7 a=8 a=9 a=10

Example 2:

#include<stdio.h>
#include<conio.h>
void main()
{
for(int a=0; a<=10;a++)
{
printf("a= %d \t",a);
}
getch();
clrscr();
}

Output:

a=0 a=1 a=2 a=3 a=4 a=5 a=6 a=7 a=8 a=9 a=10

Example 3:

#include<stdio.h>
#include<conio.h>
void main()
{

int a=0;
for(;a<=10;a++)
{
printf("a= %d \t",a);
}
getch();
clrscr();
}

Output:

a=0 a=1 a=2 a=3 a=4 a=5 a=6 a=7 a=8 a=9 a=10

Example 4:

#include<stdio.h>
#include<conio.h>
void main()
{
int a=0;
for(;a<=10;)
{
a++;
printf("A= %d\n",a);
}
getch();
clrscr();
}

Output:

A=1
A=2
A=3
A=4
A=5
A=6
A=7
A=8
A=9
A=10
A=11

Example 5:

#include<stdio.h>
#include<conio.h>
void main()
{
for(int a=0;a<=10;)
{
a++;
printf("A= %d \n",a);
}
getch();
clrscr();
}

Output:

A=1
A=2
A=3
A=4
A=5
A=6
A=7
A=8
A=9
A=10
A=11

Nested For Loop in C:

C

2 thoughts on “For loop in C”

  1. Pingback: Prime Number Program in C (top 21+ examples) - IT Examples

  2. Pingback: Reverse a String in C ( 5+ Best examples) - IT Examples

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top