Hi there!
The program to print B pattern in the C language is easy. To understand the structure of the program let's see the algorithm of the programAlgorithm of program
step 1: Start
step 2: Initialize variables a,j,b,i
step 3: Read a from user
step 4: b=(a\2)+1
step 5: Repaet the step until i=a
step 5.1: print one space
step 5.2: print *(star)
step 6: Repeat the step until j=b+1
step 7: if i=1 or i=b or i= a
step 7.1: if j=b+1
step 7.2: print one space
step 7.3: Else
step 7.4: print *
step 7.5: if i not =1 and i not = b and i not = a
step 7.6: print *
step 7.7: Else
step 7.8: print one space
step 8: print new line
step 9: Stop
Program
#include
#include
int main()
{
int a,j,i,b;
printf("entera a number");
scanf("%d",&a);
b=(a/2)+1;
for(i=1;i<=a;i++)
{
printf(" ");
printf("*");
for(j=1;j<=b+1;j++)
{
if(i==1|i==b||i==a)
{if(j==b+1)
{printf(" ");}
else
{printf("*");}}
if(i!=1&&i!=b&&i!=a)
{
if(j==b+1)
{printf("*");}
else{printf(" ");}
}
}
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