Sunday, June 26, 2011

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

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...