Question : Write a C program to print the following triangle:
*
***
*****
*******
*********
************
Answers :
#include<stdio.h>
#include<conio.h>
void
main()
{
clrscr();
int
n,j,k,i;
printf(“Enter
the number: “);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
for(k=i;k<n;k++)
{
printf(“*”);
}
for(j=1;j<=i;j++)
{
printf(“*”);
}
for(j=i;j>1;j--)
{
printf(“*”);
}
printf(“\n”);
}
getch();
}
No comments:
Post a Comment