How to write a code for printing pattern in 2023
According to students now a days in C Programming one of the most challenging and logical part is pattern printing. There are several types of pattern popular with the students. For developing logic, this type of programs play a very important role. So I have designed this code as easy as possible for the students. They will be able to understand each and every step very easily.
Before going for this type of program a student should go through basics of loop and nested loop. So that they can easily go through each step with self explanation mode. This type of logic basically helps a student to understand different nested loop structure and mathematical approach towards a code. Different mathematical equation are used to convert it into pattern. Form more code click here. For video tutorial on several topics click here.
#include <stdio.h>
int main()
{
int i,j,m,k=1;
printf("Enter the height : ");
scanf("%d",&m);
for(i=1;i<=m;i++)
{
for(j=1;j<=m;j++)
if(j<=k)
printf("%d",j);
else
printf(" ");
for(j=j-2;j>=1;j--)
{
if(j<=k)
printf("%d",j);
else
printf(" ");
}
printf("\n");
k++;
}
}