Answer to Question #289052 in C for Bryan

Question #289052

A c program to generate the below pascal triangle.




1




1 1




1 2 1




1 3 3 1




1 4 6 4 1




1 5 10 10 1





1
Expert's answer
2022-01-20T08:28:09-0500


#include <stdio.h>
#include <conio.h>


long calculateFactorial(int number);


void main()
{
	int i, n=6, j;
	for (i = 0; i < n; i++)
	{
		for (j = 0;j <= (n - i - 2); j++)
		{
			printf(" ");
		}
		for (j = 0 ; j <= i; j++)
		{
			printf("%ld ",calculateFactorial(i)/(calculateFactorial(j)*calculateFactorial(i-j)));
		}
		printf("\n");
	}
	getch();
}


long calculateFactorial(int number)
{
	int i;
	long result = 1;


	for (i = 1; i <= number; i++)
	{
		result = result*i;
	}
	return result;
}

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