C Program example: Print opposite star triangle
In this example we are going to learn how we can make a reverse star using C. In this example we are going to print ***...n in first line ,***..n-1 followed by one space,***..n-2 followed by 2 space and so on.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,n;
clrscr();
printf("Enter a number\t");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=n;j>=i;j--)
printf("* ");
printf("\n");
for(k=1;k<=i;k++)
printf(" ");
}
getch();
}
Output: Enter a number 5
* * * * *
* * * *
* * *
* *
*