![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: turbo c |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |
| ||||
| Is it your homework? |
| The Following User Says Thank You to siLenTz For This Useful Post: | ||
TeraTask (12-05-2007) | ||
| The Following 2 Users Say Thank You to siLenTz For This Useful Post: | ||
HelloWorld (12-04-2007), TeraTask (12-05-2007) | ||
| ||||
| Luckily you meet with my nice friend SiLent, other than him, I won't help you out if you won't give us what you got so far lol... |
| The Following User Says Thank You to HelloWorld For This Useful Post: | ||
TeraTask (12-05-2007) | ||
| |||
| |
| ||||
| It's better if you can use the CODE tag... Code: printf("%39d ",a[1][1]);
a[2][1]=1;a[2][2]=2;a[2][3]=1;
printf("\n%37d %d %d ",a[2][1],a[2][2],a[2][3]);
for(i=3;i<=n;i++)
{
a[i][1]=1;
printf("\n%36d ",a[i][1]);
j=2;c=3;
while(j<=i)
{
a[i][j]=a[i-1][c-1]+a[i-1][c-2];
printf("%d ",a[i][j]);
c=c+1;
j=j+1;
}
a[i][j]=1;
printf("%d",a[i][j]);
}
getch();
}
*******************output*********************
enter how many lines you want: 7
1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
i have problems in making the shape a triangle.. HINT: there's sequence of space on the triangle, print that one first, then you print the number |
| The Following User Says Thank You to HelloWorld For This Useful Post: | ||
TeraTask (12-05-2007) | ||
| |||
| Code: #include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10];
int i,j,c,n;
clrscr();
printf("enter how many line do you want: ");
scanf("%d",&n);
a[1] [1]=1;
printf("%39d ",a[1][1]);
a[2][1]=1;a[2][2]=2;a[2][3]=1;
printf("\n%37d %d %d ",a[2][1],a[2][2],a[2][3]);
for(i=3;i<=n;i++)
{
a[i][1]=1;
printf("\n%36d ",a[i][1]);
j=2;c=3;
while(j<=i)
{
a[i][j]=a[i-1][c-1]+a[i-1][c-2];
printf("%d ",a[i][j]);
c=c+1;
j=j+1;
}
a[i][j]=1;
printf("%d",a[i][j]);
}
getch();
}
*******************output*********************
enter how many lines you want: 7
1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
i have problems in making the shape a triangle.. |
| ||||
| I was surprised because you didn't know how to make it shape like Pyramid. It's not hard; you only need to create one loop for print repeated tabs. For example: I want to print 5 rows of Pascal Triangle. In this case, for the first row I would print 5 tabs; for the second row, I will print 4 tabs.; and so on. And each number will be 2 tabs distance from each other. Here my output concept: (___ represent for tab) ___ ___ ___ ___ ___ 1 ___ ___ ___ ___ 1__ ___ 1 ___ ___ ___ 1__ ___ 2__ ___ 1 ___ ___ 1__ ___ 3__ ___ 3__ ___ 1 ___ 1__ ___ 4__ ___ 6__ ___ 4__ ___1 |
| The Following User Says Thank You to siLenTz For This Useful Post: | ||
HelloWorld (12-05-2007) | ||
![]() |
| Thread Tools | |
| Display Modes | |
| |