## 9.01.2011

### 2. Design triangle pyramid

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(sp=r; sp>1; sp--)
printf(" ");
for(c=1; c<=num; c++)
printf("#");
printf("\n");
}
getch();
return 0;
}

/*************OUTPUT**************
Enter loop repeat number(rows): 5
#####
####
###
##
#
***********************************/

1. sir please tell me about the program in details with hint i am unable to understand .

1. Kindly describe what you want to know in above program?

2. i think the variable r is not needed here; y r u using that.

1. @saranya,
variable 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.

3. could you please explain how the program is creating the space ?/
I am struggling with this..

4. Just not able to understand pyramids and triangles in C. can anyone recommend a book

5. Too difficult to understand..can anyone explain?

6. for(sp=r; sp>1; sp--)
printf(" ");

7. How can you make a pyramid in HTML using jsp

8. #include
main()
{
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");
}
}