[ create a new paste ] login | about

Link: http://codepad.org/v9vRwert    [ raw code | output | fork ]

C, pasted on Jul 6:
#include <stdio.h>
#define min(a,b) a<b?a:b

void
put_nchar(int ch, int no)
{
  while (no-- > 0)
    putchar(ch);
}

void
put_nchar2(int no)
{
  while (no) {
    put_nchar('*', 1);
    put_nchar(' ', no - 2);
    put_nchar('*', (no > 1));
    no--;
    put_nchar('\n', 1);
  }
}

int
main(void)
{
  int             i, j, ln;
  printf("何段ですか:");
  scanf("%d", &ln);
  for (i = 1; i <= ln; i++) {
    j = i * 2 - 1;
    put_nchar('*', min(j, ln * 2 - j));
    put_nchar('\n', 1);
  }
  put_nchar2(ln);
  return (0);
}


Output:
1
何段ですか:


Create a new paste based on this one


Comments: