Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #27708

Re: Write a program to print star using * ?

Message-ID <508A021C.387C@mindspring.com> (permalink)
Date 2012-10-25 23:23 -0400
From pete <pfiland@mindspring.com>
Organization PF
Newsgroups comp.lang.c
Subject Re: Write a program to print star using * ?
References <9291e324-bdc8-4153-b40e-4c53fc4bcec3@googlegroups.com> <b0814c0d-1dad-465e-bb14-73e5469254fc@googlegroups.com> <5086F3C1.2FED@mindspring.com> <1btxtky76l.fsf@new-snowball.wb.pfeifferfamily.net> <508791B0.4173@mindspring.com>

Show all headers | View raw


pete wrote:
> 
> Joe Pfeiffer wrote:
> >
> > pete <pfiland@mindspring.com> writes:
> >
> > > Nikhil Joshi wrote:
> > >>
> > >> On Tuesday, October 23, 2012 9:22:33 PM UTC+5:30, Nikhil Joshi wrote:
> > >> > guys help me in making thi program?
> > >>
> > >> main()
> > >> {
> > >> int i,j;
> > >>  for(i=0;i<5;i++)
> > >> {
> > >>  for(j=i;j<5;j++)
> > >> {
> > >> printf("*");
> > >> printf("\n");
> > >> }
> > >> }
> > >> getch();
> > >> }
> > >>
> > >> this is basic structure printing star..
> > >> but dont know how make a program for star?
> > >
> > > /* BEGIN new.c */
> 
> > Hey -- don't just do his homework for him!
> 
> /* BEGIN star.c output */

And now, 
because it's almost the same program,
something that resembles a Koch snowflake:

/* BEGIN snowflake.c output */

                      *****
                     ******
                  ** ****** ***
                *****************
                *****************
                ** *** ** *** ***
                ******    *******
                *****      *****
      *****     *****      *****      *****
     ******     ******    *******     ******
  ** ****** *** ** *** ** *** *** *** ** *** **
*************************************************
*************************************************
** *** ** *** ****** ****** *** *** ****** *** **
******    *******    ******     *******    ******
*****      *****     ******      *****      *****
*****      *****       **        *****      *****
******    *******               *******    ******
** *** ** *** ***               *** *** *  *** **
*****************               *****************
*****************               *****************
 *** ****** ***                   *** ** *** ***
     ******                           ******
     ******                           ******
      *****                           *****
     ******                           ******
  ** ****** ***                   *** ** *** **
*****************               *****************
*****************               *****************
** *** ** *** ***               *** ****** *** **
******    *******               *******    ******
*****      *****                 *****      *****
*****      *****       **        *****      *****
******    *******    ******     *******    ******
** *** ** *** ***    ******     *** *** *  *** **
******************** ****** *** *****************
*************************************************
 *** ****** *** ***************** *** ** *** ***
     ******     ****** ** *******     ******
     ******     ******    *******     ******
       **        ***        ***         **
                ******    *******
                ******    *******
                ** *** ** *** ***
                *****************
                ****************
                  *  ******  *
                     ******
                      ****

/* END snowflake.c output */






/* BEGIN snowflake.c */

#include <stdio.h>
/*
** Running time is O(D*D*D*D)
*/
#define D           50
#define NMEMB(A)    (sizeof (A) / sizeof *(A))   

int 
main(void)
{
    size_t i, x, y;
    unsigned ran;
    char array[D][D + 1];
    char *const a = *array;
    long unsigned seed = 123456789LU;
    const struct {
        size_t x;
        size_t y;
    } point[] = {
        {            0, D / 2 - 1},
        {D * 3 / 4 - 1,         0},
        {D * 3 / 4 - 1,     D - 1},
        {        D / 4,         0},
        {        D / 4,     D - 1},
        {        D - 1, D / 2 - 1}
    };

    for (i = 0; i != sizeof array; ++i) {
        a[i] = ' ';
    }
    for (i = 0; i != sizeof array; a[i - 1] = '\n') {
        i += sizeof *array;        
    }
    x = point[1].x;
    y = point[1].y;
    for (i = 0; i != sizeof array * sizeof array; ++i) {
        seed = seed * 69069LU + 362437LU & 0XFFFFFFFFLU;
        ran = (unsigned) (seed / 65536) % 32768;
        x = (point[ran % NMEMB(point)].x * 2 + x) / 3;
        y = (point[ran % NMEMB(point)].y * 2 + y) / 3;
        array[x][y] = '*';
    }
    puts("/* BEGIN snowflake.c output */\n");
    for (i = 0; i != sizeof array; ++i) {
        putchar(a[i]);
    }
    puts("/* END snowflake.c output */");
    return 0;
}

/* END snowflake.c */




-- 
pete

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Write a program to print star using * ? Nikhil Joshi <nitin.nitinperderusted.rastogi@gmail.com> - 2012-10-23 08:52 -0700
  Re: Write a program to print star using * ? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-10-23 09:56 -0600
  Re: Write a program to print star using * ? Nikhil Joshi <nitin.nitinperderusted.rastogi@gmail.com> - 2012-10-23 09:03 -0700
    Re: Write a program to print star using * ? James Kuyper <jameskuyper@verizon.net> - 2012-10-23 12:35 -0400
    Re: Write a program to print star using * ? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-10-23 10:45 -0600
    Re: Write a program to print star using * ? pete <pfiland@mindspring.com> - 2012-10-23 15:45 -0400
      Re: Write a program to print star using * ? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-10-23 19:45 -0600
        Re: Write a program to print star using * ? pete <pfiland@mindspring.com> - 2012-10-24 02:58 -0400
          Re: Write a program to print star using * ? pete <pfiland@mindspring.com> - 2012-10-25 23:23 -0400
            Re: Write a program to print star using * ? Lew Pitcher <lpitcher@teksavvy.com> - 2012-10-26 09:52 -0400
              Re: Write a program to print star using * ? pete <pfiland@mindspring.com> - 2012-10-26 20:35 -0400
  Re: Write a program to print star using * ? "copiga@h_o_t_mail.co.uk" <copiga@h_o_t_mail.co.uk> - 2012-10-23 11:21 -0500
  Re: Write a program to print star using * ? "BartC" <bc@freeuk.com> - 2012-10-23 17:25 +0100
  Re: Write a program to print star using * ? Kenneth Brody <kenbrody@spamcop.net> - 2012-10-23 13:21 -0400
  Re: Write a program to print star using * ? Lew Pitcher <lpitcher@teksavvy.com> - 2012-10-23 21:59 -0400
  Re: Write a program to print star using * ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-10-27 06:05 -0700

csiph-web