Pascal Triangle in C programing
Good day programers,
This a simple C program that ask the user to input number of lines
he/she want's and generate a pascal triangle starts with one and when
the count is greater than two it multiply it self by two, after it reach
the half of the triangle it divide it self by two and stop in one(1),
this c program is an example of an nested loop,
I hope it helps you!
Code:
#include
//dont copy pls.. takes me 2 hours to figure this out..
main()
{
int n, a, k, number = 1, space = n;
printf("Enter number of lines: ");
scanf("%d",&n);
printf("\n\n");
space = n;
for ( a = 1 ; a <= n ; a++ )
{
for ( k = space ; k > 1 ; k-- )
printf(" ");
space--;
for ( k = 1 ; k <= 2*a - 1 ; k++ )
{
if ( k <= a)
{
printf("%2d ", number);
number*=2;
}
else
{
number/=2;
printf("%2d ", number/2);
}
}
number = 1;
}
return 0;
}
//if triangle is not straight try to adjust the spacing..
//coded: byruz