Pages

Tuesday, 14 February 2017

Triangle Of Asterisk '*' in C Language

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





Output

Enter a number 
5
    *
   * * 
  * * *
 * * * * 
* * * * *