C Program to display the numbers in X pattern

Refer an algorithm given below for the C program to display the numbers in X pattern.

Algorithm

Step 1: Start
Step 2: Declare variables
Step 3: Read number of rows
Step 4: for loop satisfies
  • if(i==j || i+j==rows-1)
    • print i+1
  • Print " "
Step 5: Print new line Step 6: Stop

The logic to print numbers in X pattern is as follows −

for(i=0;i");
}

Program

Following is the C program to display the numbers in X pattern −

#include
main(){
   int i,j,rows;
   printf("Enter number of rows:
");    scanf("%d",&rows);    for(i=0;i");    } }

Output

When the above program is executed, it produces the following result −

Enter number  of rows:10
1           1
  2        2
    3    3
      4 4
       55
       66
      7 7
    8     8
  9        9
10          10
Updated on: 2021-03-26T07:37:30+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements