Hi welcome!
![]() |
| D pattern |
the program to print D patterns in the C language is easy. let's get deep in the program by understanding the program algorithm.
Algorithm of Program
step 1: intial variables a,b,c,i,
step 2: read variabl value by user in put
step 3: assign b=a and c=a-3
step 4:Repeat the step until i=a
step 4.1: print *
step 4.2: repeat the step until j=b
step 4.2.1: if i=1 or i=a
step 4.2.2: print *
step 4.2.3: else if j=b
step 4.2.4: print one space
step 4.2.5: if i<=3
step 4.2.6: variable b increament
step 4.2.7: if i>=c
step 4.2.8: variable b decreament
step 4.3 : print new line
step 5:stop
Program
#include
#include
int main()
{
int a,b,c,i,j;
printf("enter number:");
scanf("%d",&a);
b=a;c=a-3;
for(i=1;i<=a;i++)
{
printf("*");
for(j=1;j<=b;j++)
{
if(i==1||i==a)
{
printf("*");
}
else if(j==b)
{printf("*");}
else
{printf(" ");}}
if(i<=3)
{b++;}
else if(i>=c)
{b--;}
printf("\n");}
getch();
return 0;
}
Output
ok, if you have any doubt feel free to contact us. if you want any program in C language please comment we will try our level best.
Thank you for visiting.



0 Comments