hii... i really need help... pls help...
so my question is:
how to write a c program to print pascal triangle using for loop ?
its output should be like this
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
pls guyzz i need to submit it tmrww...
thnx in advance
kvnmurty:
check my solution it is very brief. and it is easily understood.
Answers
Answered by
0
#include<stdio.h>
long fact(int);
int main()
{
int line,i,j;
printf("Enter the no. of lines: ");
scanf("%d",&line);
for(i=0;i<line;i++){
for(j=0;j<line-i-1;j++)
printf(" ");
for(j=0;j<=i;j++)
printf("%ld ",fact(i)/(fact(j)*fact(i-j)));
printf("\n");}
return 0;}
long fact(int num)
{ long f=1;
int i=1;
while(i<=num)
{ f=f*i; i++; }
return f;
}
if this helped u...
pls let me know by marking it best! ;) :)
long fact(int);
int main()
{
int line,i,j;
printf("Enter the no. of lines: ");
scanf("%d",&line);
for(i=0;i<line;i++){
for(j=0;j<line-i-1;j++)
printf(" ");
for(j=0;j<=i;j++)
printf("%ld ",fact(i)/(fact(j)*fact(i-j)));
printf("\n");}
return 0;}
long fact(int num)
{ long f=1;
int i=1;
while(i<=num)
{ f=f*i; i++; }
return f;
}
if this helped u...
pls let me know by marking it best! ;) :)
i'm just an amateur...
i just tried as i saw your question and I've got it!!
and i'll see if i could help u the way you want!!
Answered by
0
#include <stdio.h>
main()
{
int row, H , j ;
printf("Height of triangle: ");
scanf("%d", &H);
for (row=1; row <= H ; row++ )
for (j = row; j >= 1 ; j--) // print integers, starting from row number up to 1
printf("%d ", j);
}
main()
{
int row, H , j ;
printf("Height of triangle: ");
scanf("%d", &H);
for (row=1; row <= H ; row++ )
for (j = row; j >= 1 ; j--) // print integers, starting from row number up to 1
printf("%d ", j);
}
Similar questions
Math,
1 year ago
Math,
1 year ago
Social Sciences,
1 year ago
Biology,
1 year ago
Chemistry,
1 year ago