Ticker

6/recent/ticker-posts

C Language (For loop)

FOR LOOP IN C
The For loop is a simplest loop among all the loops of C language because its all the statements (Initialization, Increment/Decrement, Test condition) written only in one statement. 



PRINT COUNTING 1-10 BY FOR LOOP
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
for(i=0; i<=10; i++)
{
printf("\n%d",i);
}
getch();
}

----------------------------
         OUTPUT 
----------------------------

1
2
3
4
5
6
7
8
9
10


PRINT REVERSE COUNTING 10-1 BY FOR LOOP
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
for(i=10; i>=; i--)
{
printf("\n%d",i);
}
getch();
}

----------------------------
         OUTPUT 
----------------------------

10
9
8
7
6
5
4
3
2
1

PRINT MATHS TABLE FOR A GIVEN NUMBER
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,n;
printf("Enter any number:");
scanf("%d",&n);
for(i=1; i<=10; i++)
{
printf("\n%d x %d = %d", n, i, n*i);
}
getch();
}

----------------------------
         OUTPUT 
----------------------------




























Post a Comment

0 Comments