## 9.01.2011

### 5.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,c,sp;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
{
for(sp=num-r; sp>=1; sp--)
printf(" ");
for(c=1; c<=r; c++)
printf("@");
printf("\n");
}
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5

 @ @ @ @ @ @ @ @ @ @ @ @ @ @ @

***********************************/

1. sir can u please tell me in details what is the work of "sp--"..

1. Sp-- tell us about the decrease of space in the pattern like
ssssss@
sssss@@
ssss@@@
sss@@@@
ss@@@@@
s@@@@@@
Here 's' indicates the decreasing order of space in pattern. Just like sp

2. this is wrong

3. This is wrong plz tell correct solution

1. the program is correct

2. Anish Pls run it once!!! Program is absolutely correct..

5. tell me the c program for following structure:
1 1
12 21
123 321
1234 4321
123454321

1. #include

int main(void) {
int rows,i,k;
int ary[10];
scanf("%d",&rows);

for(i=1;i<=rows;i++)
{
for(k=1;k<=i;k++)
{
ary[k]=k;
printf("%d",k);
}
printf(" ");
for(k=(k-1);k>=1;k--)
{
printf("%d",ary[k]);
}
printf("\n");
}

return 0;
}

6. =1; \$space--)

printf("&nbsp&nbsp&nbsp&nbsp");
for(\$c=0; \$c<=\$r; \$c++)

echo "@";
echo"
";
}

?>

7. import java.util.*;
class Pattern5
{
public static void main(String[] args)
{
System.out.println("Enter the number of rows:");
Scanner sc=new Scanner(System.in);
int num=sc.nextInt(); //Number of rows taking from keyboard

for(int row=1;row<=num;row++) // NUmber of rows
{
for(int space=num;space>row;space--)
{
System.out.print(" ");
}

for(int col=1;col<=row;col++) //column stars printing
{
System.out.print("#");
}
System.out.println();

}
}
}

8. There is no basic difference between the following programs. But when I run these two they show difference shaped pyramids. Can anybody tell me why?
................................................................................................
Programe of Q. NO-5 of this blog:

#include
#include
void main()
{
clrscr();
int num=5,r,c,sp;
for(r=1;r<=num;r++)
{
for(sp=num-r;sp>=1;sp--)
{
printf(" ");
}
for(c=1;c<=r;c++)
{
printf("*");
}
printf("\n");
}
getch();
}
........
my programe:

#include
#include
void main()
{
clrscr();
int row, space, star;
for(row = 1; row<=5; row++)
{
for(space = 5-row; space >=0; space--)
{
printf(" ");
}
for(star = 1; star<=row; star++)
{
printf(" * ");
}
printf("\n");
}
getch();
}

1. Your program is right...thank u..

9. #include
main()
{
int i,j,k,n;
printf("Enter the number of rows");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=n;k>i;k--)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("@");
}
printf("\n");
}
}

10. 12,
12,13,
13,14,12,
15,12,13,14,
13,14,15,16,12,
16,17,12,13,14,15,
13,14,15,16,17,18,12,
17,18,19,12,13,14,15,16,
13,14,15,16,17,18,19,20,12,
18,19,20,21,12,13,14,15,16,17,
13,14,15,16,17,18,19,20,21,22,12,