Q. Write a program to generate a following #'s triangle?
# | # | # | # | # |
# | # | # | # | |
# | # | # | ||
# | # | |||
# |
Ans.
/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r=1,c,sp;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(; num>=1; num--,r++)
for(; num>=1; num--,r++)
{
for(sp=r; sp>1; sp--)
for(sp=r; sp>1; sp--)
printf(" ");
for(c=1; c<=num; c++)
printf("#");
printf("\n");
}
getch();
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
#####
####
###
##
#
***********************************/
/*************OUTPUT**************
Enter loop repeat number(rows): 5
#####
####
###
##
#
***********************************/
sir please tell me about the program in details with hint i am unable to understand .
ReplyDeleteKindly describe what you want to know in above program?
Deletei think the variable r is not needed here; y r u using that.
ReplyDelete@saranya,
Deletevariable r is useful for calculate the white/blank space, so the courser goes to right position.
Without 'r' variable, the space laps and output may be differ.
could you please explain how the program is creating the space ?/
ReplyDeleteI am struggling with this..
Just not able to understand pyramids and triangles in C. can anyone recommend a book
ReplyDeleteToo difficult to understand..can anyone explain?
ReplyDeletefor(sp=r; sp>1; sp--)
ReplyDeleteprintf(" ");
How can you make a pyramid in HTML using jsp
ReplyDelete#include
ReplyDeletemain()
{
int i,j,k,n;
printf("Enter the number of rows");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=1;k=i;j--)
{
printf("@");
}
printf("\n");
}
}