How do I print a diagonal pattern?

How do I print a diagonal pattern?

Program in C to display the diagonal number pattern

  1. int i, j, n, k=1 ; printf(” Enter the Maximum Number : “) ; scanf(“%d “, & n) ; for ( i = 1 ; i <= (2 * n ) – 1 ; i++ ) {
  2. if ( i == j || i + j == 2 * n ) printf(” %d ” , k) ; else. printf(” “) ;
  3. } if ( i < n ) k++ ; else. k– ;

How do you create a star pattern in Java?

1. Right Triangle Star Pattern

  1. public class RightTrianglePattern.
  2. {
  3. public static void main(String args[])
  4. {
  5. //i for rows and j for columns.
  6. //row denotes the number of rows you want to print.
  7. int i, j, row=6;
  8. //outer loop for rows.

How do you print diagonal stars in Python?

“Write a python program to print the given number of diagonal lines of stars” Code Answer

  1. rows = 6 #Pattern(1,121,12321,1234321,123454321)
  2. for i in range(1, rows + 1):
  3. for j in range(1, i – 1):
  4. print(j, end=” “)
  5. for j in range(i – 1, 0, -1):
  6. print(j, end=” “)

How do I print an array diagonally?

Start from the index (0,0) and print the elements diagonally upward then change the direction, change the column and print diagonally downwards. This cycle continues until the last element is reached. Algorithm: Create variables i=0, j=0 to store the current indices of row and column.

How do you print a star?

  1. #include
  2. int main()
  3. int row, c, n, temp;
  4. printf(“Enter the number of rows in pyramid of stars you wish to see “);
  5. scanf(“%d”,&n);
  6. temp = n;
  7. /* Program to print star pattern */
  8. for ( row = 1 ; row <= n ; row++ )

How do you print an asterisk in Python?

Print star or number Use the print() function in each iteration of nested for loop to display the symbol or number of a pattern (like a star (asterisk * ) or number).