C Program to Print Cross or X Pattern Last Updated : 10 Dec, 2024 Comments Improve Suggest changes Like Article Like Report The Cross or X Pattern is a pattern where characters or stars are printed diagonally from top-left to bottom-right and from top-right to bottom-left, forming an "X" shape. In this article, we will learn how to print this pattern using a C program. Program to Print Cross or X Pattern Star Cross #include <stdio.h> int main() { int i, j; int c; // Number of rows and columns for the pattern int n = 5; c = n * 2; // Loop through each row for (i = 0; i < 2 * n - 1; i++) { // Loop through each column in the row for (j = 0; j < 2 * n - 1; j++) { // Print a star at the diagonal position if (j == i || j == 2 * n - 2 - i) printf("*"); else printf(" "); } printf("\n"); } return 0; } Number Cross #include <stdio.h> int main() { int i, j; int c; // Number of rows and columns for the pattern int n = 5; c = n * 2; // Loop through each row for (i = 0; i < 2 * n - 1; i++) { // Loop through each column in the row for (j = 0; j < 2 * n - 1; j++) { // Print a star at the diagonal position if (j == i || j == 2 * n - 2 - i) printf("%d", j + 1); else printf(" "); } printf("\n"); } return 0; } Alphabet Cross #include <stdio.h> int main() { int i, j; int c; // Number of rows and columns for the pattern int n = 5; c = n * 2; // Loop through each row for (i = 0; i < 2 * n - 1; i++) { // Loop through each column in the row for (j = 0; j < 2 * n - 1; j++) { // Print a star at the diagonal position if (j == i || j == 2 * n - 2 - i) printf("%c", j + 'A'); else printf(" "); } printf("\n"); } return 0; } Output* * | 1 9 | A I * * | 2 8 | B H * * | 3 7 | C G * * | 4 6 | D F * | 5 | E * * | 4 6 | D F * * | 3 7 | C G * * | 2 8 | B H * * | 1 9 | A IExplanation:The outer loop controls the number of rows to print. It runs 2 * n - 1 times, which for n = 5 means 9 iterations (rows).The inner loop controls the number of columns printed in each row. Like the outer loop, it runs 2 * n - 1 times, i.e., 9 iterations for n = 5.Inside the inner loop, the condition j == i prints stars along the first diagonal (top-left to bottom-right) and j == 2 * n - 2 - i prints stars along the second diagonal (top-right to bottom-left).If neither condition is true, a space ( ) is printed. Comment More infoAdvertise with us Next Article Programs to print Interesting Patterns S syedanwarmashalkar073 Follow Improve Article Tags : Technical Scripter C Programs C Language Technical Scripter 2022 Similar Reads Pattern Programs in C Printing patterns using C programs has always been an interesting problem domain. We can print different patterns like star patterns, pyramid patterns, Floyd's triangle, Pascal's triangle, etc. in C language. These problems require the knowledge of loops and if-else statements.We will discuss the fo 15+ min read C Program For Printing Right Half Pyramid Pattern A half-right pyramid consists of rows with sequential stars, numbers or characters arranged in a triangular shape. The first row has one character, the second row has two, and so on. The characters are aligned to the left making it similar to the right-angle triangle. In this article, we will learn 5 min read C Program to Print Pyramid Pattern In C, a pyramid pattern consists of numbers, stars, or alphabets arranged in a triangular shape. In this article, we will learn how to print different shapes of pyramid patterns using C program.Following are the 6 common pyramid patterns:Right Half Pyramid PatternRight half pyramid pattern looks lik 13 min read C Program to Print Number Pattern A number pattern involves printing numbers in a specific arrangement or shape, often in the form of a pyramid, triangle, or other geometric shapes. They are great for practicing loops and conditional statements. In this article, we will learn how to print different number patterns in C.Rhombus Numbe 6 min read C Program to Print Continuous Character Pattern Here, we will see how to print continuous character patterns using a C program. Below are the examples: Input: rows = 5Output: A B C D E F G H I J K L M N O Input: rows = 3Output: A B C D E F There are 2 ways to print continuous character patterns in C: Using for loop.Using while loop. Let's discuss 5 min read C Program To Print Character Pyramid Pattern Pyramid patterns is a classic logical programming exercise where a triangular looking pattern is printed by treating the output screen as a matrix and printing a given character. In this article, we will explore how to print various alphabet pyramid patterns using C program.Half Pyramid PatternHalf 4 min read C Program to Print Right Half Pyramid Pattern The Right Half Pyramid Pattern is a triangular pattern consists of rows where each row contains an increasing number of characters. The number of characters starts from 1 and increases by 1 in each subsequent row. Characters are aligned to the left, resembling a right-angle triangle with its hypoten 2 min read C Program To Print Hollow Pyramid Patterns The Hollow Pyramid patterns are the variation of pyramid patterns where only the outer edges are filled with characters but the interior is left empty. In this article, we will learn how to print different hollow pyramid patterns.There can be 5 hollow pyramid patterns corresponding to each of the no 12 min read C Program to Print Cross or X Pattern The Cross or X Pattern is a pattern where characters or stars are printed diagonally from top-left to bottom-right and from top-right to bottom-left, forming an "X" shape. In this article, we will learn how to print this pattern using a C program. Program to Print Cross or X PatternStar Cross#includ 3 min read Programs to print Interesting Patterns Program to print the following pattern: Examples : Input : 5Output:* * * * * * * * * ** * * * * * * ** * * * * ** * * ** ** ** * * ** * * * * ** * * * * * * ** * * * * * * * * *This program is divided into four parts.C++// C++ program to print // the given pattern #include<iostream> using name 15+ min read Like