Hello everyone!
I tried a lot to understand the spacing procedure in pascal triangle.. but it all went to vein!!

Does anyone knows about this spacing???

Why are we using this loop:

for(x=40-3*y;x>0;--x)
 printf(" ");

need help ASAP!!

I tried a lot to understand the spacing procedure in pascal triangle.. but it all went to vein!!

do you mean the spacing between the integers on every line?
you need to be more specific on how you need the triangle to look like,
does it require you to use recursive functions?

also have you checked examples from the web like these, are they similar to what you require?
http://www.roseindia.net/tutorial/C/pascalTriangle.html
http://www.programmingsimplified.com/c-program-print-pascal-triangle

i want the triangle to be lookin like an equilateral triangle...

but the point is, why are we employing 40-3*y??? or anything like this??? how we come to know that this thing will give proper spacing???

here's a sample program I used that implements your code, if you have a specific code you're using feel free to post it:

int main() {

        int a[15][15], i, j, rows, num = 40, x;
        printf("\n Enter the number of rows:");
        scanf("%d", &rows);
        for (i = 0; i < rows; i++) {

               for (x = 40 - 3 * i; x > 0; x--)
                     printf(" ");

               for (j = 0; j <= i; j++) {
                     if (j == 0 || i == j) {
                         a[i][j] = 1;
                     } else {
                         a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
                     }
                     printf("%4d", a[i][j]);
               }
               printf("\n");
         }
    return 0;
}

if you input 6, its output looks like

                                           1
                                        1   1
                                     1   2   1
                                  1   3   3   1
                               1   4   6   4   1
                            1   5  10  10   5   1

which doesn't look equilateral to me (according to my terminal), is it required for you to use that?
and here's something that gives an equilateral look for me

               for (x = 25 - 2 * i; x >= 0; x--)
                     printf(" ");

which gives out this when the input is 6:

                             1
                           1   1
                         1   2   1
                       1   3   3   1
                     1   4   6   4   1
                   1   5  10  10   5   1

note: im using linux gcc as a compiler and this "might" look different on other compilers

what you've shown me is correct!! but is there any way to know that 25-2i or 40-3i will give me what i want???
sorry if i'm annoying you.. :(

what you've shown me is correct!! but is there any way to know that 25-2i or 40-3i will give me what i want???

Yes. Sit down at your desk with pencil and paper and plug values into the variables. See what values are generated and draw out what they indicate.

Pretty much what you'd do in any math class. Works in programming, too.

commented: true story +9

hehe..!! :) Thanks!! that'd be better!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.