Home Forums Re: Pascal’s Triangle source code plzz

#3448
Humayan
Participant

could try:

#include 
#include
int main()
{
    int numberOfLevels, i, j , k, spaces = 5;
    printf ( "How many rows you want to show?: ");
    scanf ( "%d", &  numberOfLevels);
    for ( i = 0; i < numberOfLevels; i ++ )
 {
        int currentElement = 1;
        k = 0;
        while ( k < spaces )
        {
            printf ( " " );
            k ++;
        }
        for ( j = i; j >= 0; j -- )
  {
            printf ( " %d", currentElement );
            currentElement = currentElement * j / ( i - j + 1 );
        }
        printf("n");
        spaces --;
    }
}