I really need a sample program in C programming where in the output to be displayed is a TRIANGLE using asterisk(*). Please help me about this matter. Thank you.
Can you give me the syntax code in C programming where in the output is a TRIANGLE using asterisk(*).?
If you want simple, then just use a series of printf statements...
printf("*");
printf("**");
printf("***");
printf("****");
printf("*****");
There are of course other ways to do it. that are much more elegant.
Reply:u didnt defined the type of triangle u want......
1)
#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
void main()
{
clrscr();
int i, j ,n;
printf("enter the limit = ");
scanf("%d",%26amp;n);
for(i=1;i%26lt;=n;i++)
{
for(j=i;j%26lt;=i,j--)
{
printf("*");
}
printf("\n");
}
getch();
}
2) for 2nd type of tringle.....loop will be(jus change above loop into these one)
for(i=1;i%26lt;=n;i++)
{
for(j=1;j%26lt;=n-i;j--)
{
printf("*");
}
printf(\n");
}
getch();
}
3)for 3rd kind of trinangle........again chane (1) loop into dese..
for(i=1;i%26lt;=n;i++)
{
printf("\n");
for(j=1;j%26lt;=n-i;j++)
{
printf(" ");
}
for(j=1;j%26lt;=(i*2)-1;j++)
{
printf("*");
}
}
getch();
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment