Q. Write a program to generate a following numbers triangle:(Where user entered number through keyboard, for example if num=5)
1 | ||||||||
1 | 2 | 1 | ||||||
1 | 2 | 3 | 2 | 1 | ||||
1 | 2 | 3 | 4 | 3 | 2 | 1 | ||
1 | 2 | 3 | 4 | 5 | 4 | 3 | 2 | 1 |
Ans.
/*c program for number triangle pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c,sp,x;
printf("Enter loop repeat number(rows):");
scanf("%d",&num);
for(r=1; num>=r; r++)
for(r=1; num>=r; r++)
{
for(sp=num-r; sp>=1; sp--)
printf(" ");
for(c=1; c<=r; c++)
printf("%d",c);
for(x=r-1; x>=1; x--)
printf("%d",x);
printf("\n");
}
getch();
getch();
return 0;
}
/****************OUTPUT***************
Enter loop repeat number(rows): 5
**************************************/
/****************OUTPUT***************
Enter loop repeat number(rows): 5
1 | ||||||||
1 | 2 | 1 | ||||||
1 | 2 | 3 | 2 | 1 | ||||
1 | 2 | 3 | 4 | 3 | 2 | 1 | ||
1 | 2 | 3 | 4 | 5 | 4 | 3 | 2 | 1 |
**************************************/
#include
ReplyDelete#include
main()
{
int i,j,n=10,y,z=1;
for(i=0;i<=n;i++)
{
for(j=n;j>0;j--)
{
printf(" ");
}
for(y=0;y<z;y++)
{
printf("*");
}
n--;
z=y+2;
printf("\n");
}
}
plz post algorithm of dis progm
ReplyDeletecan you give me the control flow of this program??
ReplyDeletecan ur gud slf plz give the code for
ReplyDelete1
232
34543
4567654
567898765
4567654
34543
232
1
Hi Shahid,
ReplyDeleteHere is the code for your Pattern.
#include
int main()
{
int n=5,i,j,k1,k2,c,c1=0;
//Code for Upper Traingle
for(i=1;i<=n;i++)
{
k1=i-1;
c=0;
for(j=1;j<=i;j++) {
printf("%3d",++k1);
++c;
}
for(;c>1;c--)
printf("%3d",--k1);
printf("\n");
}
//Code for Bottom reverse Traingle
--i;
for(;i>=1;i--)
{
k2=i-1;
c=0;
for(j=1;j1;c--)
printf("%3d",--k2);
printf("\n");
}
return 0;
}
Can anyone give code for this pattern:
ReplyDelete0
101
21012
3210123
432101234
54321012345
@Monica,
DeleteYour required above Number Triangle Pattern C program source code at:
http://cprogrammingcodes.blogspot.com/2014/08/number-triangle-pattern-c-program.html
Hy Monika how to I print numerical pyramid in
DeleteCan anyone give code for this pattern:
ReplyDelete.....1*1
....2****2
...3******3
..4********4
5**********5
..4********4
...3******3
....2****2
......1*1
@Sudhanshu Sharma,
DeleteYour required number rhombus pattern C program source code at:
http://cprogrammingcodes.blogspot.com/2014/08/how-to-design-number-rhombus-pattern-c.html
can anyone give me code for following pattern??
ReplyDelete###1###
##121##
#13331#
1444441
(# reprents blank space)
Deleteint n = 5;
int initial = 1;
for(int i = 1; i<=n; i++){
for(int j=n-i; j>=0; j--){
System.out.print(" ");
}
for(int k = 0; k<(i*2)-1;k++){
if(k==0){
System.out.print(initial);
} else if( k==(i*2)-2){
System.out.print(initial);
} else {
System.out.print(i);
}
}
System.out.println();
}
1
ReplyDelete2 4 6
1 3 5 7 9
2 4 6 8 10 12 14
1 3 5 7 9 11 13 15 17
@Cyber Hacker,
DeleteYour required Odd and Even number pattern program in C as:
http://goo.gl/Xr39qb
I need help with the following pattern:
ReplyDeleteA
ABA
ABCBA
ABCDCDA
ABCDEDCBA
The pattern should extend to the character entered.
For example, the preceding pattern would result from an input value of E.
#Gabriela Espino
DeleteYour character triangle pattern C program source code as:
http://cprogrammingcodes.blogspot.com/2014/02/character-pyramid.html
Example
ReplyDeleteIf input is 2, output will be
00006
00028 00066
If input is 3, output will be
00006
00028 00066
00120 00190 00276
provide code for this output
Code this pyramid plz.
ReplyDelete0
1 0 1
2 1 0 1 2
3 2 1 0 1 2 3
4 3 2 1 0 1 2 3 4
Code for this pyramid plz
ReplyDelete0
1 0 1
2 1 0 1 2
3 2 1 0 1 2 3
4 3 2 1 0 1 2 3 4
Reks Singh
DeleteYour number pattern C program source code at:
https://cprogrammingcodes.blogspot.in/2014/08/number-triangle-pattern-c-program.html
0
ReplyDelete101
21012
3210123 plse give me answer for c++
#Tarunendra Patel,
Deleteyour required number triangle pattern program source code at:
https://goo.gl/FgPph5
what would be the code for the pattern :
ReplyDelete***0***
**101**
*21012*
3210123
(Here * are nothing but the blank spaces . . .)
Please give me code for
ReplyDelete1
121
13331
1444441