1 1
2 2
3
4 4
5 5
Problem statement:- Program to Print Cross Sign (╳ ) Number Pattern.
Data requirement:-
Input Data:- row_size
Output Data:- out
Additional Data:-in or inn(for python)
Program in C
Here is the source code of the C Program to Print Cross Sign (╳ ) Number Pattern.
Code:
#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("%d",out);
}
else
{
printf(" ");
}}
printf("\n");
}}
Input/Output:
Enter the row size:5
1 1
2 2
3
4 4
5 5
Program in C++
Here is the source code of the C++ Program to Print Cross Sign (╳ ) Number Pattern.
Code:
#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<<out;
}
else
{
cout<<" ";
}
}
cout<<"\n";
}
}
Enter the row size:7
1 1
2 2
3 3
4
5 5
6 6
7 7
Program in Java
Here is the source code of the Java Program to Print Cross Sign (╳ ) Number Pattern.
Code:
import java.util.Scanner;
public class NumberPattern20 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
System.out.println("Enter the row size(odd number):");
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.print(out);
}
else
{
System.out.printf(" ");
}
}
System.out.println();
}
cs.close();
}
}
Enter the row size(odd number):
5
1 1
2 2
3
4 4
5 5
Program in Python
Here is the source code of the Python Program to Print Cross Sign (╳ ) Number Pattern.
Code:
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(out,end="")
else:
print(" ", end="")
print("\r")
Enter the row size:5
1 1
2 2
3
4 4
5 5
0 Comments
Please do not Enter any spam link in the comment box