Answer to Question #288681 in C for Bryan

Question #288681

A c program that generates the Pascal's triangle.

1
Expert's answer
2022-01-19T10:36:12-0500
#include <stdio.h>
#include <conio.h>


long factorial(int n)
{
	int c;
	long result = 1;


	for (c = 1; c <= n; c++)
	{
		result = result*c;
	}
	return result;
}


void main()
{
	int i, n, c;
	printf("Enter the number of rows: ");
	scanf("%d",&n);


	for (i = 0; i < n; i++)
	{
		for (c = 0; c <= (n - i - 2); c++)
		{
			printf(" ");
		}
		for (c = 0 ; c <= i; c++)
		{
			printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));
		}
		printf("\n");
	}
	getch();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS