
- Forum
- Programming Talk
- C and C++
- pascal's triangle in c
pascal's triangle in c
This is a discussion on pascal's triangle in c within the C and C++ forums, part of the Programming Talk category; program in c for pascal's triangle... i hav read in different books but i cant understand the logic....... is there ...
-
02-28-2008, 01:17 PM #1
- Join Date
- Feb 2008
- Answers
- 5
pascal's triangle in c
program in c for pascal's triangle...
i hav read in different books but i cant understand the logic.......
is there any simple logic without pointers and functions
i want a simple program........
can anybody help me out
-
The program to calculate the Pascal triangle is given below:
#include<stdio.h>
#include<conio.h>
void main()
{
int k[10][10];
int i,j,s,l;
printf("How many lines?");
scanf("%d",&l);
k[1][1]=1;
printf("%5d",k[1][1]);
k[2][1]=1;k[2][2]=2;k[2][3]=1;
printf("%d %d %d",k[2][1],k[2][2],k[2][3]);
for(i=3;i<=l;i++)
{
k[i][1]=1;
printf("%d",k[i][1]);
j=2;s=3;
while(j<=i)
{
k[i][j]=k[i-1][s-1]+k[i-1][s-2];
printf("%5d",k[i][j]);
s=s+1;
j=j+1;
}
k[i][j]=1;
printf("%d",k[i][j]);
}
}
Let me know if you are struck with any other programs in C.
-
12-17-2009, 02:13 PM #3
- Join Date
- Dec 2009
- Answers
- 1
sry .. this program is not working....
-
12-26-2010, 02:00 AM #4
- Join Date
- Dec 2010
- Answers
- 32
following code will print this pascal triangle...
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
till n;
where n=limit;;;
#inlcude<conio.h>
#include<stdio.h>
void main()
{
int i,j,n;
printf("Enter the value of n\n");
scanf("%d",&n)
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
simple change in the for loop will generate the opposite triangle////
54321
4321
321
21
1
for(i=n;i>=1;i--)
{
for(j=1;j<=i;j++)
{
everything remains the same
-
thx it was very simple plain programfollowing code will print this pascal triangle...
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
till n;
where n=limit;;;
#inlcude<conio.h>
#include<stdio.h>
void main()
{
int i,j,n;
printf("Enter the value of n\n");
scanf("%d",&n)
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
simple change in the for loop will generate the opposite triangle////
54321
4321
321
21
1
for(i=n;i>=1;i--)
{
for(j=1;j<=i;j++)
{
everything remains the same
-
Sponsored Ads

Reply With Quote






