Solution
Program in C++
The C++ Program to Print Cross Sign (╳) source code is available here. Star Pattern.
#include<iostream>
using namespace std;
int main()
{
cout<<"Enter the row size:";
int row_size;
cin>>row_size;
int in,out,p;
for(out=1;out<=row_size;out++)
{
for(in=1;in<=row_size;in++)
{
if(in==out || in+out==row_size+1)
{
cout<<"*";
}
else
{
cout<<" ";
}
}
cout<<"\n";
}
}

You can also try this code with Online C++ Compiler
Run Code
Output:
Enter the row size:7
* *
* *
* *
*
* *
* *
* *

You can also try this code with Online C Compiler
Run Code
Program in C
The C Program to Print Cross Sign (╳ ) source code is available here, Star Pattern.
#include<stdio.h>
int main()
{
int out,in;
printf("Enter the row size:");
int row_size;
scanf("%d",&row_size);
for(out=1;out<=row_size;out++)
{
for(in=1;in<=row_size;in++)
{
if(in==out || in+out==row_size+1)
{
printf("*");
}
else
{
printf(" ");
}}
printf("\n");
}}

You can also try this code with Online C Compiler
Run Code
Input/Output:
Enter the row size:5
* *
* *
*
* *
* *
Program in Java
The Java Program to Print Cross Sign (╳) Star Pattern source code is available here.
import java.util.Scanner;
public class StarPattern17 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
System.out.println("Enter the row size:");
int out,in;
int row_size=cs.nextInt();
for(out=1;out<=row_size;out++)
{
for(in=1;in<=row_size;in++)
{
if(in==out || in+out==row_size+1)
{
System.out.printf("*");
}
else
{
System.out.printf(" ");
}
}
System.out.println();
}
cs.close();
}
}

You can also try this code with Online Java Compiler
Run Code
Input/Output:
Enter the row size:
5
* *
* *
*
* *
* *
Program in Python
The Python Program to Print Cross Sign (╳) Star Pattern source code is available here.
row_size=int(input("Enter the row size:"))
print_control_x=row_size//2+1
for out in range(1,row_size+1):
for inn in range(1,row_size+1):
if inn==out or inn+out==row_size+1:
print("*",end="")
else:
print(" ", end="")
print("\r")

You can also try this code with Online Python Compiler
Run Code
Input/Output:
Enter the row size:3
* *
*
* *
In all the above examples, the output will be a pattern in the form of a Cross Sign.
Input Format
The first line contains the row size of the pattern, while the other variables were for the internal and external of the pattern.
Output Format
We are printing the pattern in the form of a Cross Sign.
Check out this problem - Check If A String Is Palindrome
Frequently Asked Questions
Why are Patterns essential to learn?
Patterns help us make predictions of what will happen. Next, It helps us develop logical connections and improve our reasoning skills
What Is A Design Pattern?
A design pattern is a general repeatable solution to a typically occurring problem in software design in software engineering. A design pattern isn't a finished design that can be turned into code right away. It's a description or template for solving an issue that may be applied to a variety of scenarios.
Conclusion
In this article, we have learned the Cross Sign pattern using the stars. We also explained it works and how it will go through step by step. We also took the example and the output of the pattern.
Recommended Readings:
Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, etc. on Coding Ninjas Studio.
Also check out some of the Guided Paths on topics such as Interview Puzzles, Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.