C++ : Segitiga Pascal

Standard

next, segitiga pascal. dengan input tinggi segitiga yang di inginkan

#include 

main()
{
	int a,b,c,d,e,in;
	int A[100]={0,1};
	int B[100];
	int C[100];

	printf("Masukkan tingi segitiga:");
	scanf("%d",&in);

	a=0;
	b=1;
	d=in;
	e=d;

	while(b<=in)
	{
		while(d>=1)
		{
			printf("  ");
			d--;
		}

		c=0;
		while(c<=a)
		{
			B[c]=A[c]+A[c+1];
			C[c+1]=B[c];
			printf("%d   ",B[c]);
			c++;
		}

		C[0]=0;
		C[a+2]=0;

		c=0;
		while(c<=a+2)
		{
			A[c]=C[c];
			c++;
		}

		a++;
		b++;

		d=e;
		d--;
		e=d;

		printf("\\n");
	}
}

dipahami dulu baru nanya ya, 😀 next assignment : Sorting Number

Leave a Reply