Write a C program that prints an equilateral triangle for a given n.
For n=3
*
**
***
**
*
For n=4
*
**
***
****
***
**
*
CODE:
main()
{
int i,j,num;
printf("Enter
num");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
for(i=num-1;i>=1;i--)
for(j=1;j<=i;j++)
{
printf("*");\
}
printf("\n");
}
return 0;
}
Program Output:
For more problems click here
No comments:
Post a Comment