#include <stdio.h>
int main()
{
int lines=8;
int i,j,k;
for(i=1;i<lines;i++){// this loop is used to print the lines
for(j=1;j<=lines/2;j++){// this loop is used to print numbers
if(i==j){
printf("%d",j);
}
else if(i>4 && j==lines-i){
printf("%d",j);
}
else{
printf(" ");
}
}
j=j-2;
while(j>0){ // this loop is used to print numbers
if(i==j){
printf("%d",j);
}
else if(i>4 && j==lines-i){
printf("%d",j);
}
else{
printf(" ");
}
j--;
}
printf("\n");
}
return 0;
}
Output:
Java Program:
public class pattern{
public static void main(String []args){
int lines=8;
int i,j,k;
for(i=1;i<lines;i++){// this loop is used to print the lines
for(j=1;j<=lines/2;j++){// this loop is used to print numbers
if(i==j){
System.out.print(j);
}
else if(i>4 && j==lines-i){
System.out.print(j);
}
else{
System.out.print(" ");
}
}
j=j-2;
while(j>0){ //this loop is used to print numbers
if(i==j){
System.out.print(j);
}
else if(i>4 && j==lines-i){
System.out.print(j);
}
else{
System.out.print(" ");
}
j--;
}
System.out.println("");
}
}
}
Output:
C# Program:
using System;
public class Program
{
public static void Main()
{
int lines=8;
int i,j;
for(i=1;i<lines;i++){// this loop is used to print lines
for(j=1;j<=lines/2;j++){// this loop is used to print lines
if(i==j){
Console.Write(j);
}
else if(i>4 && j==lines-i){
Console.Write(j);
}
else{
Console.Write(" ");
}
}
j=j-2;
while(j>0){ //this loop is used to print lines
if(i==j){
Console.Write(j);
}
else if(i>4 && j==lines-i){
Console.Write(j);
}
else{
Console.Write(" ");
}
j--;
}
Console.WriteLine();
}
}
}
Output:
PHP Program:
$lines=8;
$i=1;
$j=1;
for($i=1;$i<$lines;$i++){// this loop is used to print lines
for($j=1;$j<=$lines/2;$j++){ // this loop is used to print lines
if($i==$j){
echo $j;
}
else if($i>4 && $j==$lines-$i){
echo $j;
}
else{
echo ' ';
}
}
$j=$j-2;
while($j>0){// this loop is used to print lines
if($i==$j){
echo $j;
}
else if($i>4 && $j==$lines-$i){
echo $j;
}
else{
echo " ";
}
$j--;
}
echo "<br>";
}
Output:
Python Program:
lines=8
i=1
j=1
while i<lines: # this loop is used to print lines
j=1
while j<=lines/2: #this loop is used to print lines
if i==j:
print(j, end='', flush=True)
elif i>4 and j==lines-i:
print(j, end='', flush=True)
else :
print(" ", end='', flush=True)
j=j+1
j=j-2;
while j>0: #this loop is used to print lines
if i==j:
print(j, end='', flush=True)
elif i>4 and j==lines-i:
print(j, end='', flush=True)
else :
print(" ", end='', flush=True)
j=j-1
print("")
i=i+1
C Program:
Output:
Java Program:
Output:
C# Program:
Output:
PHP Program:
Output:
Python Program:
Output:

need an explanation for this answer? contact us directly to get an explanation for this answer