it is still long way to go

stop holding your self and move forward to the never ending journey

just for fun 1

leave a comment »

#include<stdio.h>
int main(int argc, char* argv) {

printf(“masukkan angka ganjil > 3:”);   int element;   scanf(“%d”, &element);   if(element%2!=0&&element>3) {

int center=element/2;   int k,l;   int m=center-1;

for(k=0;k<element;k++) {

for(l=0;l<element;l++) {

if(k<=center) {

if(l==(center-k)||l==(center+k))

{              printf(“#”);           } else {              printf(” “);           }        } else if(k>center) {           if(l==(center-m)||l==(center+m)) {              printf(“#”);           } else {              printf(” “);           }        }      }      if(k>center) {         m–;      }      printf(“\n”);   }   } else {      printf(“input genab atau kurang dari 5″);   }   return 0;

}

just to fill my spare time. I think the if condition can be more simple, even it can be done with a single if. :)

 

Advertisement

Written by gentur

December 23, 2010 at 5:40 am

Posted in C, Programming

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.