Learn about Half Diamond Pattern Programs Using Numbers in C in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Half Diamond Pattern Programs Using Numbers in C
To print a pattern as below follow the below C code.
1 12 123 1234 12345 1234 123 12 1
Program:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n, place, a;
printf("Enter number of rows: ");
scanf("%d",&n);
for(int i=1; i< 2*n; i++)
{
a=1;
if(i < n) place=i;
else place = abs(2*n-i);
for(int j=1; j<=place; j++)
printf("%d",a++);
printf("\n");
}
return 0;
}
Output:
Enter number of rows: 5 1 12 123 1234 12345 1234 123 12 1
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
C Program to Print Mirrored Half Diamond Star Pattern
C Program to Print Half Diamond Star Pattern