Header Ads

Hii,I am Anand Nayak.This blogger is make for specially basic programs of some language.

Print alphbaet in diamond shape with for loop

#include<stdio.h>
#include<conio.h>
  void main()
  {
  int s,r,l=1,k;
  char ch='A',z='Z';
  clrscr();
  for(r=1;r<=3;r++)
  {
     for(s=1;s<=3-r;s++)
       printf(" ");
     for(k=1;k<=2*r-1;k++)
     {
       if(l%2!=0)
       {
printf("%c",ch++);

}
     else
     {
printf("%c",z--);

     }
l++;
      } printf("\n");
  }
  for(r=3;r>=1;r--)
  {
     for(s=1;s<=3-r;s++)
       printf(" ");
     for(k=1;k<=2*r-1;k++)
     {
       if(l%2!=0)
       {
printf("%c",ch++);

}
     else
     {
printf("%c",z--);

     }
l++;
      } printf("\n");
  }
   getch();
}

No comments