How to Program the Four Ways of Triangle Using Asterisk in C


How to program the four ways of triangle with asterisk ‘*’ in C
Today, I’ll be showing you how to code a simple program by entering the number of range or rows of a half triangle.


#include<stdio.h>
int main()
{
int rows,i,j,k=0;
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=1;i<=rows;i++)
{
for(j=rows;j>=i;--j)
printf("*",k+j);
++k;
printf("\n");
}
int l;
for ( i = 0 ; i <= rows ; i++)
{
for(k=1; k<=rows-i; k++)
{
printf(" ");
}
for(j=0; j<i; j++)
{
printf("*");
}
printf("\n");
}
printf("\n");

for (i=rows-1; i>=0; i--)
{
for(l=(rows-2)-i; l>=0; l--)
{
printf(" ");
}
for (k=i; k>=0; k--)
{
printf("*");
}
printf("\n");
}
printf("\n");
for(i=1; i<=rows; ++i)
{
for(j=1; j<=i; ++j)
{
printf("*");
}
printf("\n");
}
}


RESULT:


How to Program the Four Ways of Triangle Using Asterisk in C How to Program the Four Ways of Triangle Using Asterisk in C Reviewed by code-dev on 10:32 PM Rating: 5

No comments:

Powered by Blogger.