[go: up one dir, main page]

0% found this document useful (0 votes)
54 views3 pages

Pattern 2

The document contains code to print Pascal's triangle. The code takes the number of rows as input, then uses nested for loops to print the correct number of spaces and asterisks to create each row of the triangle. Each row has one fewer star than the previous row on both sides.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views3 pages

Pattern 2

The document contains code to print Pascal's triangle. The code takes the number of rows as input, then uses nested for loops to print the correct number of spaces and asterisks to create each row of the triangle. Each row has one fewer star than the previous row on both sides.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

* * * * * * * * *

* * * * * * *

* * * * *

* * *

#include<stdio.h>
int main()
{
int rows, i, j, space;

printf("Enter number of rows: ");


scanf("%d",&rows);

for(i=rows; i>=1; --i)


{
for(space=0; space < rows-i; ++space)
printf(" ");

for(j=i; j <= 2*i-1; ++j)


printf("* ");

for(j=0; j < i-1; ++j)


printf("* ");
printf("\n");
}

return 0;
}

1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

#include <stdio.h>
int main()
{
int rows, coef = 1, space, i, j;

printf("Enter number of rows: ");


scanf("%d",&rows);

for(i=0; i<rows; i++)


{
for(space=1; space <= rows-i; space++)
printf(" ");
for(j=0; j <= i; j++)
{
if (j==0 || i==0)
coef = 1;
else
coef = coef*(i-j+1)/j;

printf("%4d", coef);
}
printf("\n");
}

return 0;
}

You might also like