## 9.02.2011

### 10. Design numbers tringle pyramid

Q. Write a program to generate a following numbers triangle:
(Where user entered number through keyboard, for example if num=5)

1
12
123
1234
12345
Ans.

/* c program for number triangle*/
#include<stdio.h>
int main()
{
int num,r,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; r<=num; r++)
{
for(c=1; c<=r; c++)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}

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

1
12
123
1234
12345

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

Related Pyramid Programs in C:

1. i believe i am doing something wrong. but thanks a million to the programmer. it didn't work out trying to figure out....

1. @banta savrait khanda,
Above program is working, Write down your program for discuss and solutions.

2. I am going to recheck it this evening when I come home.

1. I comment above program in two lines bcoz C is working according to compiler. So you can check your program in different compiler.

3. I wants Write a program to generate a numbers triangle using while please explain me

4. how to print
1234
2341
3421
4321

5. how to print
1234
2341
3421
4321

1. void main()
{
int i,j,k;
clrscr();
for(i=1;i<5;i++)
{
for(j=i;j<5;j++)
{
printf("%d",j);
}
k=i;
while(k>1)
{
printf("%d",k-1);
k--;
}
printf("\n");
}
getch();
}

2. void main()
{
int i,j,k;
clrscr();
for(i=1;i<5;i++)
{
for(j=i;j<5;j++)
{
printf("%d",j);
}
k=i;
while(k>1)
{
printf("%d",k-1);
k--;
}
printf("\n");
}
getch();
}

6. how to print a
a
ab
abc
abcd

1. @Karthik, your required character pattern design C program source code at:

#include"stdio.h"
int main()
{
char ch,r,c;
printf("Enter any character : ");
scanf("%c", &ch);
if(ch>='a' && ch<='z')
ch=ch-32;
for(r='A'; r<=ch; r++)
{
for(c='A'; c<=r; c++)
printf("%c", c);
printf("\n");
}
getch();
return 0;
}

1. @Toki Tahmid Inan,

Your required Number Pyramid Source Code at:

#include"stdio.h"
int main()
{
int num,r,c,n;
printf("Enter Any Number : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=1,n=num; c<=r; c++,n--)
printf("%d", n);
printf("\n");
}
getch();
return 0;
}

7. 1
1 3
1 3 5
1 3 5 7

1. @ Nahidul Islam

Your required odd number triangle source code as:

#include"stdio.h"
int main()
{
int num,r,c,z;
printf("Enter no. of rows : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=1,z=1; c<=r; c++,z=z+2)
printf("%d ",z);
printf("\n");
}
getch();
return 0;
}

8. Hey please can u give me souce code for this
1
**
234
****
5678

1. @ Nogs Mujeeb

Your required symbol number triangle C program source code as:

#include"stdio.h"
int main()
{
int num=5,r,c,p=1,q;
for(r=1; r<=num; r++)
{
if(r%2==0)
{
for(c=r; c>=1; c--)
printf("*");
}
else
{
for(c=r; c>=1; c--,p++)
printf("%d",p);
}
printf("\n");
}
getch();
return 0;
}

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

for(j=0;j<=i;j++)
{

printf("%d",l);
l++;
}

printf("\n");
}
}

10. 5
4 4
3 3 3
2 2 2 2
1 1 1 1 1
pls reply fr this pattern

1. # Lalit Kumar

Source code for above number triangle pyramid program source code as:

#include "stdio.h"
int main()
{
int num,r,c,n;
printf("Enter loop start no. : ");
scanf("%d",&num);
n=num;
for(r=1; r<=num; r++,n--)
{
for(c=1; c<=r; c++)
printf(" %d",n);
printf("\n");
}
getch();
return 0;
}

/******Output*******/

Enter loop start no. : 5
5
4 4
3 3 3
2 2 2 2
1 1 1 1 1