
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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 " "
The logic to print numbers in X pattern is as follows −
for(i=0;i<rows;i++){ for(j=0;j<rows;j++){ if(i==j || i+j==rows-1){ printf("%d",i+1); }else{ printf(" "); } } printf("
"); }
Program
Following is the C program to display the numbers in X pattern −
#include<stdio.h> main(){ int i,j,rows; printf("Enter number of rows:
"); scanf("%d",&rows); for(i=0;i<rows;i++){ for(j=0;j<rows;j++){ if(i==j || i+j==rows-1){ printf("%d",i+1); }else{ printf(" "); } } printf("
"); } }
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
- Related Articles
- C program to represent the numbers in spiral pattern
- C++ Program to Print X Star Pattern
- Program to print a pattern of numbers in C++
- C++ Program to Print Spiral Pattern of Numbers
- C program to display the prime numbers in between two intervals
- Print numbers in matrix diagonal pattern in C Program.
- C++ Program to Display Prime Numbers Between Two Intervals
- Java Program to Print X Star Pattern
- Golang Program To Print X Star Pattern
- Swift Program To Print X Star Pattern
- C program to display numbers in reverse order using single linked list
- Java Program to Print Spiral Pattern of Numbers
- Golang Program to Print Spiral Pattern of Numbers
- C++ Program to Display Prime Numbers Between Two Intervals Using Functions
- C program to represent the alphabets in spiral pattern

Advertisements