Printing Star patterns using LOOPS

 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




Try this




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


try this






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


Try this






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;
}



No : 5


try this





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;

}



No : 6



TRY THIS


CODE :

#include<stdio.h>
int main()
{
int i,j;
for ( i = 1; i <= 5 ; i++)
{
for ( j = 1; j <= i ; j++)
{
printf("%2i", j);
}
printf("\n");
}
return 0;
}




Designed by : M . I Afthal Ahamad
                                 ICT/ 2022 /105
                                 AA3644

Post a Comment

0 Comments