C Programming - Program Membuat Diamond

Posted by Posted by batercusblack On 2:55 PM


#include <stdio.h>

int main()
{
 int i, j, t, start, space;
 printf("Masukkan jumlah diamond di baris tengah: ");
 scanf("%d",&amp;t);

 if(t%2 == 0)
 {
  start = 2;
 }
 else
     {
         start = 1;
     }

     space = t/2;
     i=start;
 while(i&lt;=t)
     {
  for(j=1; j&lt;=space; j++)
   printf(" ");
          space--;
             for(j=1; j&lt;=i; j++)
              printf("*");
              printf("\n");
      i=i+2;
     }

 space = start;
        i=(t-2);
 while(i&gt;=start)
     {
         for(j=1; j&lt;=space; j++)
   printf(" ");
   space++;
             for(j=1; j&lt;=i; j++)
              printf("*");
              printf("\n");
      i=(i-2);
     }
 return 0;
}

suka dengan artikel ini? klik disini

0 comments

Post a Comment