Number Patterns
To printing number pattern using for loop, first we should know about for loop
and how it can use in pattern programming.
Syntax
The syntax of a for loop in C is:
for(init; condition1; increment/decrement)
{
--
----
statement(s);
}
Examples :-
1. 12345
1234
123
12
1
code for above output.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=5;i<=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
2. 1
12
123
1234
12345
No comments:
Post a Comment