For a better practice with loops & to understand the loops printing star patters will give you an idea how the loops work .
Lets print these patterns one by one
No : 1
Try this |
CODE :
#include<stdio.h>
int main()
{
int i,j;
for ( i = 1 ; i <= 6 ; i++)
{
for( j = 1 ; j <= i; j++)
{
printf("*" );
}
printf("\n");
}
return 0;
}
No : 2
CODE :
#include<stdio.h>
int main()
{
int i,j;
for ( i = 1; i <= 5 ; i++)
{
for ( j = 1; j <= 7; j++)
{
printf("* ");
}
printf("\n");
}
return 0;
}
No : 3
CODE :
#include<stdio.h>
int main()
{
int i,j;
for ( i = 6; i >= 1; --i)
{
for ( j = i; j >= 1 ; --j)
{
printf("* ");
}
printf("\n");
}
return 0;
}
No : 4
CODE :
#include<stdio.h>
int main()
{
int i,j,s;
for ( i = 1 ; i <= 6 ; i++)
{
for ( s = i ; s < 6 ; s++)
{
printf(" ");
}
for ( j = 1 ; j <= i ; j++)
{
printf("* ");
}
printf("\n");
}
return 0;
}
CODE :
#include<stdio.h>
int main()
{
int i,j,s;
for ( i = 1 ; i <= 6 ; i++)
{
for ( s = 1 ; s < i ; s++)
{
printf(" ");
}
for ( j = 6; j >= i ; j--)
{
printf("* ");
}
printf("\n");
}
return 0;
}
0 Comments