answersLogoWhite

0

the logic i have used is nCr => n!/(r!*(n-r)!) for example the outer loop counter is 'n' and the inner loop counter is 'r' , then the corresponding element of the pascal's triangle will be nCr. keep in mind that both the loops will have to start from zero. #include<stdio.h> main()

{

int num,i,j,k,space;

int difffact=1,diff,n,r,x,y,comb=0,nfact=1,rfact=1;

printf("please enter the number of lines\n");

scanf("%d",&num); k=num-1;

space=num-1;

for(i=0;i<num;i++)

{

k=space--;

for(;k>0;k--)

{

printf(" ");

}

for(j=0;j<=i;j++)

{

comb=0;

nfact=1;

rfact=1;

difffact=1; for(n=i;n>=1;n--)

nfact=nfact*n; for(r=j;r>=1;r--)

rfact=rfact*r; diff=i-j;

for(;diff>=1;diff--)

difffact=difffact*diff; comb=(nfact/(rfact*difffact));

printf("%d ",comb);

}

printf("\n");

}

}

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

What is the time complexity of using a while loop inside a for loop?

The time complexity of using a while loop inside a for loop is O(nm), where n is the number of iterations of the for loop and m is the number of iterations of the while loop.


For loop program turbo c making a right triangle?

yes


Write a program to display the even number series using for loop?

int maxNum = 1000; for(int i = 0; i &lt;= maxNum; i += 2) { // Java solution System.out.println(i); // C solution printf("%d\n", i); }


Write a program that input a positive integer and prints a triangle using for loop?

write a program that reads in the size of the side of square and then pints a hollow square of that size out of asterisks and blanks?


How do you prepare a right angled triangle of using for loop?

for(int i=1;i&lt;=n;i++) { for(int j=1;j&lt;=i;j++) { print what u need } print to go to next line }


What is a mobius loop?

A mobius loop is the symbol often reffered to as the recycling symbol. It consits of three arrows pointing at eachother, forming a type of triangle.


When a sequential search uses a for loop a break statement is used to end the loop when a match is found?

It is a possible solution, yes.


Flow chart using for loop?

There's a nice for Loop at the link below.


How do you exit in nested loop in java?

You may exit a nested loop in Java using a break with a label for the outer loop.


How can you create a loop using a knot?

To create a loop using a knot, you can make a simple overhand knot in a rope or string and leave a small loop at the end. This loop can be used for various purposes such as attaching a hook or securing an object.


Fibonacci series using for loop in HTML?

HTML has no notion of a loop. This cannot be done.


How do you print square using for loops?

how to print "square" using for loop