Computer Science, asked by aditikathare, 1 year ago

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 Ronny321
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! ;) :)

aditikathare: tthnx a lot.....
aditikathare: but i hv one confusion , i need this only with for loop nd u hv usd while loop nd also wat abt dis fact...???
Ronny321: hello!!
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!!
aditikathare: thnk u so mch...!!!!
aditikathare: pls...... did u get the answer..???
AvmnuSng: what have you done? the pattern is not what you are printing.....
Answered by kvnmurty
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);
    
}


AvmnuSng: This is the exact and perfect solution
kvnmurty: If you like the solution, rate the answer as brainliest please.
Similar questions