5
45
345
2345
12345
012345
12345
2345
345
45
5
Problem statement:- Program to print the Solid Half Diamond Number Pattern.
Data requirement:-
Input Data:- row_size
Output Data:- p
Additional Data:-out, in or inn(for python)
Program in C
Here is the source code of the C Program to print the Solid Half Diamond Number Pattern.
Code:
#include<stdio.h>
#include<math.h>
int main()
{
printf("Enter the row size:");
int row_size;
scanf("%d",&row_size);
int in,out,p;
for(out=row_size;out>=-row_size;out--)
{
for(in=1;in<=abs(out);in++)
printf(" ");
for(p=abs(out);p<=row_size;p++)
printf("%d",p);
printf("\n");
}
}
Enter the row size:5
5
45
345
2345
12345
012345
12345
2345
345
45
5
Program in C++
Here is the source code of the C++ Program to print the Solid Half Diamond Number Pattern.
Code:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
cout<<"Enter the row size:";
int row_size;
cin>>row_size;
int in,out,p;
for(out=row_size;out>=-row_size;out--)
{
for(in=1;in<=abs(out);in++)
cout<<" ";
for(p=abs(out);p<=row_size;p++)
cout<<p;
cout<<"\n";
}
}
Enter the row size:4
4
34
234
1234
01234
1234
234
34
4
Program in Java
Here is the source code of the Java Program to print the Solid Half Diamond Number Pattern.
Code:
import java.util.Scanner;
public class NumberPattern18 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int out,in,p;
System.out.println("Enter the row size:");
int row_size=cs.nextInt();
for(out=row_size;out>=-row_size;out--)
{
for(in=1;in<=Math.abs(out);in++)
System.out.printf(" ");
for(p=Math.abs(out);p<=row_size;p++)
System.out.print(p);
System.out.println();
}
cs.close();
}
}
Enter the row size:
5
5
45
345
2345
12345
012345
12345
2345
345
45
5
Program in Python
Here is the source code of the Python Program to print the Solid Half Diamond Number Pattern.
Code:
row_size=int(input("Enter the row size:"))
for out in range(row_size,-(row_size+1),-1):
for in1 in range(1,abs(out)+1):
print(" ",end="")
for p in range(abs(out),row_size+1):
print(p,end="")
print("\r")
Enter the row size:3
3
23
123
0123
123
23
3
0 Comments
Please do not Enter any spam link in the comment box