answersLogoWhite

0


Best Answer

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

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

8y ago

Hi the way u explained the logic and the program You have done is, perfect.But jus two things You need to concentrate for printing the pyramid in a right shape.I have included changes .. You.

#include

#include

/*program to generate pascal triangle, no. of lines r to be entered by the user*/

void main()

{

int a,b,c,i,j,n,r,s,ncr,factr,factn,factnr,line;

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

scanf("%d",&line); //inputs the no. of lines we want

clrscr();

for(i=0;i<=line-1;i++)//outer loop for the value of n

{

factn=1;// reinitializing the factorial values to avoid garbage values...

factr=1;

factnr=1;

for(s=line-1;s>=i;s--) // Just Included a For loop TO have leading Spaces

{

printf(" ");

}

for(j=0;j<=i;j++) //outer loop for the values of r

{

n=i; //here we have assigned i to n and j to r for our nCr calculation and convinience

r=j;

factn=1; // again we have re initialised factorial values to avoid garbage values

factr=1;

factnr=1;

if(n==0) //we know factorial of 0 =1

factn=1;

else

{

for(a=n;a>=1;a--) //factorial calculation of n is n!=0

factn=factn*a;

}

if(r==0)

factr=1;

else

{

for(b=r;b>=1;b--) //factorial calculation of r if r!=0

factr=factr*b;

}

if((n-r)==0)

factnr=1;

else

{

for(c=(n-r);c>=1;c--) //factorial calculation of n-r if (n-r)!=0

factnr=factnr*c;

}

ncr=factn/(factr*factnr); //ncr calculation

printf("%2d",ncr); //Remove that tab and GIven 2d to have spaces between each characters and prints the value of ncr

}

printf("\n"); //cursor get to the next line when the control exits the inner loop

}

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

#include<stdio.h>

#include<conio.h>

int main()

{

unsigned int c,i,j,k;

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

{

c=1;

for(j=1;j<=2*(5-i);j++)

printf(" ");

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

{

printf("%3d",c);

c=c*(i-k)/(k+1);

}

printf("\n");

}

getch();

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include
#include
#include
void main()
{
clrscr(); int n;
cout<<"\n enter number of lines ";
cin>>n;
int a=1,b,s=1;
for(;a<=n;s=s*10+1)
{
for(b=n-a;b>=1;b--)
{
cout<<" ";
}
cout<cout<<"\n";
a++;
}

getch();
}

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

#include<iostream>

#include<string>

int pascal (const int row, const int col)

{

if (!col col==row)

return 1;

return pascal (row-1, col-1) + pascal (row-1, col);

}

int main()

{

using namespace std;

cout << "Enter a row number for Pascal's Triangle: ";

size_t rows;

cin >> rows;

for (size_t row=0; row!=rows; ++row)

{

cout << string (rows-row,'\t');

for(size_t col=0;col<=row; ++col)

cout << pascal (row,col) << "\t\t";

cout << endl;

}

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

No.

Check previous answers to this question and any other questions you may have in your course. Others before you have asked the very same questions.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

write a c program to display

*

* *

* * *

* * * *

* * *

* *

*

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the codes for pascal triangle by using pascal compiler?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Flowcharting of pascal triangle?

draw a flowchart of pascal triangle using for loops


Why did blaise pascal important contribution?

Blaise Pascal invented the Pascaline and Pascal's Triangle. Pascal's Triangle was a triangle, which started of with 1. The number underneath is worked out by adding the two numbers above it together. Using Pascal's Triangle, we can find many patterns, including Triangle Numbers.


Who invented Pascal's triangle?

Pascal's triangle was invented by Blaise Pascal (1623-1662) in 1653. Although it has been named after blaise pascal, there have been traces of the triangle, long before Blaise Pascal was born. It is belived that the Persians and the Chinese had been using it to find the square and cube root of numbers. Whoever asked this question is a complete idiot, because the answer is in the question.


How do you expand multinomials?

One way to expand multinomials is using Pascal's triangle.


Make a pascal using c plus plus?

Please make your question more clear. Qhat do you want to do? Rewrite the programming language Pascal? Convert c++ code to Pascal? Create a Pascal triangle? Make a baby son that's called Pascal? (btw, that last thing has to be done in hardware)


How do you do a project on Designs and patterns using arithmetic progressions?

You can use a couple different methods for this. Using Pascal's triangle you can keep making shapes that are bigger proportionally.


Are languages and compilers application softwares?

No. A compiler is a system software. An application can be created using a language and a compiler. A language is what you write the software with.No. A compiler is a system software. An application can be created using a language and a compiler. A language is what you write the software with.No. A compiler is a system software. An application can be created using a language and a compiler. A language is what you write the software with.No. A compiler is a system software. An application can be created using a language and a compiler. A language is what you write the software with.No. A compiler is a system software. An application can be created using a language and a compiler. A language is what you write the software with.No. A compiler is a system software. An application can be created using a language and a compiler. A language is what you write the software with.No. A compiler is a system software. An application can be created using a language and a compiler. A language is what you write the software with.No. A compiler is a system software. An application can be created using a language and a compiler. A language is what you write the software with.No. A compiler is a system software. An application can be created using a language and a compiler. A language is what you write the software with.No. A compiler is a system software. An application can be created using a language and a compiler. A language is what you write the software with.No. A compiler is a system software. An application can be created using a language and a compiler. A language is what you write the software with.


How can you make a ms-dos com program?

You would need to write it using a software development system that includes a compiler and an integrated development environment. Turbo Pascal and Euphoria are two programming languages you could use.


What did Blaise Pascal contribute to mathematics?

Pascal's triangle. It is named after the French mathematician, Blaise Pascal in much of the Western world, although other mathematicians studied it centuries before him in India, Greece, Iran, China, Germany, and Italy. The rows of Pascal's triangle are conventionally enumerated starting with row n = 0 at the top. The entries in each row are numbered from the left beginning with k = 0 and are usually staggered relative to the numbers in the adjacent rows. (Wikipedia)The top of the triangle -11 11 2 11 3 3 11 4 6 4 1And you can continue on, using the same rules.


What is file processing in pascal language?

is the way a file is design using a pascal language


What are different counting techniques?

What are the different counting techniques


How do you edits program using Linux compiler?

You don't. The compiler is used to compile programs, not edit them. Most source code can be edited using a standard text editor.