C Programming - Program Membuat Diamond

| |

#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;
}

Related Posts by Categories

0 komentar:

Posting Komentar