Alphbet E pattern using only two loops in C language

 Hello welcome!

techbin cloud


program to print E pattern in C language using only two loops. to understand better lets see the algorithm of the program 

                    Algorithm of program

step 1:start 

step 2:initial variables i,j,a,b

step 3:Read a value in a variable 'a'

step 4:assign b=(a/2)+1

step 5:repeat the step until i=a

  step 5.1:print *

  step 5.2:repeat the step untill j<a

     step 5.2.1:if i=1 or i=b or i=a

     step 5.2.2:print *

     step 5.2.3:else

     step 5.2.4:print *

step 6:print new line

step 7:stop


Program

#include<stdio.h> #include<conio.h> int main() { int i,j,a,b; printf("enter a number"); scanf("%d",&a); b=a/2+1; for(i=1;i<=a;i++) { printf("*"); for(j=1;j<a;j++) { if(i==1||i==b) printf("*"); } else {printf(" ");}} printf("\n"); } getch(); return 0; }

Output

techbin cloud


Post a Comment

0 Comments