Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Python Program to Print Pascal's Triangle, Essays (university) of English Language

A simple python program to print pascal's triangle based on the number of rows entered by the user. The program uses a nested loop structure to print the triangle.

What you will learn

  • How does the Python program calculate the number of columns for each row in Pascal's Triangle?
  • What is the purpose of the nested loops in the Python program to print Pascal's Triangle?
  • Can the Python program be modified to print the reverse of Pascal's Triangle?

Typology: Essays (university)

2020/2021

Uploaded on 03/21/2021

lily-stewart
lily-stewart 🇨🇦

3 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
#include <stdio.h>
int main(int argc, char **argv)
{
int row, column, i = 0;
int userRows;
printf("Enter the number of rows: ");
scanf("%d", &userRows);
// For each row
for (row = 1; row <= userRows; row++, i = 0)
{
// For each column print spaces until first *, then print *
for(column = 1; column <= userRows - row; column++)
{
printf(" ");
}
while (i != 2 * row - 1)
{
printf("*");
i++;
}
printf("\n");
}
return 0;
}

Partial preview of the text

Download Python Program to Print Pascal's Triangle and more Essays (university) English Language in PDF only on Docsity!

#include <stdio.h> int main(int argc, char **argv) { int row, column, i = 0; int userRows; printf("Enter the number of rows: "); scanf("%d", &userRows); // For each row for (row = 1; row <= userRows; row++, i = 0) { // For each column print spaces until first , then print * for(column = 1; column <= userRows - row; column++) { printf(" "); } while (i != 2 * row - 1) { printf(""); i++; } printf("\n"); } return 0; }