[ create a new paste ] login | about

Link: http://codepad.org/kRsHtty9    [ raw code | output | fork | 1 comment ]

joshua_cheek - C, pasted on Oct 22:
#include<stdio.h>

void print_chars( char c , int how_many , char* separator )
{
  while( how_many-- ) 
    printf("%c%s" , c , how_many ? separator : "" );
}

void print_triangle( char c , int base , int indention )
{
  int i;
  for( i=0 ; i<base ; ++i )
  {
    print_chars( ' ' , indention+i , "" );
    print_chars( c , base-i , " " );
    printf("\n");
  }
}


int main()
{
  print_triangle( '*' , 5 , 3 );
  return 0;
}


Output:
1
2
3
4
5
   * * * * *
    * * * *
     * * *
      * *
       *


Create a new paste based on this one


Comments:
posted by joshua_cheek on Nov 15
Prints a triangle with optional character for body, optional size, and optional indention (the example I was fulfilling was indented and it wasn't clear whether this was a requirement, so I put it in anyway).
reply