# Diamond pattern printing using numbers | Diamond number patterns | faceprep

Programs for diamond pattern printing using numbers is discussed here.

##### Half diamond pattern printing using numbers

Input:
3  4
Output:
3
44
555
6666
555
44
3

## Program for half diamond pattern printing using numbers

/* C program for diamond pattern printing using numbers */

#include <stdio.h>
int main()
{
int i,j,s,N,count=0;
scanf(“%d%d”,&s,&N);
for(i=s;count<4;count++)
{
for(j=0;j<count+1;j++)
printf(“%d”,i);
printf(“\n”);
i=i+1;
}
for(i=s+N-2;count>0;count–)
{
for(j=0;j<count-1;j++)
printf(“%d”,i);
printf(“\n”);
i=i-1;
}
return 0;
}

/* C++ program for diamond pattern printing using numbers */

#include <iostream>
using namespace std;

int main()
{
int i,j,s,N,count=0;
cin >> s >> N;
for(i=s;count<4;count++)
{
for(j=0;j<count+1;j++)
cout << i;
cout << endl;
i=i+1;
}
for(i=s+N-2;count>0;count–)
{
for(j=0;j<count-1;j++)
cout << i;
cout << endl;
i=i-1;
}
return 0;
}

/* Java program for diamond pattern printing using numbers */

import java.util.*;

public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

int i,j,s,N,count=0;
s = sc.nextInt();
N = sc.nextInt();
for(i=s;count<4;count++)
{
for(j=0;j<count+1;j++)
System.out.print(i);
System.out.print(“\n”);
i=i+1;
}
for(i=s+N-2;count>0;count–)
{
for(j=0;j<count-1;j++)
System.out.print(i);
System.out.print(“\n”);
i=i-1;
}

}
}

Input :
4
Output:
1
2*2
3*3*3
4*4*4*4
4*4*4*4
3*3*3
2*2
1

## Program for half diamond pattern printing using numbers and stars

/* C program for diamond pattern printing using  numbers */

#include <stdio.h>
int main()
{
int i,j,k,N,count=0;
scanf(“%d”,&N);
for(i=1;i<=N;i++)
{
k=1;
for(j=0;j<i;j++)
{
printf(“%d”,i);
if(k<i)
{
printf(“*”);
k=k+1;
}
}
printf(“\n”);
}
for(i=N;i>0;i–)
{
k=1;
for(j=0;j<i;j++)
{
printf(“%d”,i);
if(k<i)
{
printf(“*”);
k=k+1;
}
}
printf(“\n”);
}
return 0;
}

/* C+ program for diamond pattern printing using numbers and stars */

#include <iostream>
using namespace std;

int main()
{
int i,j,k,N,count=0;
cin >> N;
for(i=1;i<=N;i++)
{
k=1;
for(j=0;j<i;j++)
{
cout << i;
if(k<i)
{
cout << “*”;
k=k+1;
}
}
cout << endl;
}
for(i=N;i>0;i–)
{
k=1;
for(j=0;j<i;j++)
{
cout << i;
if(k<i)
{
cout << “*”;
k=k+1;
}
}
cout << endl;
}
return 0;
}

/* Java program for diamond pattern printing using numbers and stars */

import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

int i,j,k,N,count=0;
N = sc.nextInt();
for(i=1;i<=N;i++)
{
k=1;
for(j=0;j<i;j++)
{
System.out.print(i);
if(k<i)
{
System.out.print(“*”);
k=k+1;
}
}
System.out.print(“\n”);
}
for(i=N;i>0;i–)
{
k=1;
for(j=0;j<i;j++)
{
System.out.print(i);
if(k<i)
{
System.out.print(“*”);
k=k+1;
}
}
System.out.println();
}

}
}

Input:
4
Output:
1
2*3
4*5*6
7*8*9*10
7*8*9*10
4*5*6
2*3
1

## Program to print the pattern using numbers and stars

/* C program for diamond pattern printing using numbers and stars */

#include <stdio.h>
int main()
{
int i,j,count=1,n;
printf(“Enter a number\n”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
if(j<i)
printf(“%d*”,count++);
else
printf(“%d”,count++);
}
printf(“\n”);
}
count=count-n;
for(i=n;i>=1;i–)
{ for(j=1;j<=i;j++)
{
if(j<i)
printf(“%d*”,count++);
else
printf(“%d”,count++);
}
count=(count+1)-2*i;
printf(“\n”);
}
return 0;
}

/* C++ program for diamond pattern printing using numbers and stars */

#include <iostream>
using namespace std;

int main()
{
int i,j,count=1,n;
cout << “Enter a number\n”;
cin >> n;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
if(j<i)
cout << count++ << “*”;
else
cout << count++;
}
cout << endl;
}
count=count-n;
for(i=n;i>=1;i–)
{ for(j=1;j<=i;j++)
{
if(j<i)
cout << count++ << “*”;
else
cout << count++;
}
count=(count+1)-2*i;
cout << endl;
}
return 0;
}

/* Java program for diamond pattern printing using numbers and stars */

import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

int i,j,count=1,n;
n = sc.nextInt();
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
if(j<i)
System.out.print(count++ + “*”);
else
System.out.print(count++);
}
System.out.print(“\n”);
}
count=count-n;
for(i=n;i>=1;i–)
{ for(j=1;j<=i;j++)
{
if(j<i)
System.out.print(count++ + “*”);
else
System.out.print(count++);
}
count=(count+1)-2*i;
System.out.println();
}

}
}

Output:

Half diamond printing using numbers:

Half diamond printing using numbers and stars 1:

Half diamond printing using numbers and stars 2: