C Programming - Program Membuat Diamond
Sunday, June 26, 2011 at 2:55 PM#include <stdio.h>
int main()
{
int i, j, t, start, space;
printf("Masukkan jumlah diamond di baris tengah: ");
scanf("%d",&t);
if(t%2 == 0)
{
start = 2;
}
else
{
start = 1;
}
space = t/2;
i=start;
while(i<=t)
{
for(j=1; j<=space; j++)
printf(" ");
space--;
for(j=1; j<=i; j++)
printf("*");
printf("\n");
i=i+2;
}
space = start;
i=(t-2);
while(i>=start)
{
for(j=1; j<=space; j++)
printf(" ");
space++;
for(j=1; j<=i; j++)
printf("*");
printf("\n");
i=(i-2);
}
return 0;
}