Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #27582 > unrolled thread
| Started by | Nikhil Joshi <nitin.nitinperderusted.rastogi@gmail.com> |
|---|---|
| First post | 2012-10-23 08:52 -0700 |
| Last post | 2012-10-27 06:05 -0700 |
| Articles | 16 — 9 participants |
Back to article view | Back to comp.lang.c
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
| From | Nikhil Joshi <nitin.nitinperderusted.rastogi@gmail.com> |
|---|---|
| Date | 2012-10-23 08:52 -0700 |
| Subject | Write a program to print star using * ? |
| Message-ID | <9291e324-bdc8-4153-b40e-4c53fc4bcec3@googlegroups.com> |
guys help me in making thi program?
[toc] | [next] | [standalone]
| From | Joe Pfeiffer <pfeiffer@cs.nmsu.edu> |
|---|---|
| Date | 2012-10-23 09:56 -0600 |
| Message-ID | <1bhaplyyfh.fsf@new-snowball.wb.pfeifferfamily.net> |
| In reply to | #27582 |
Nikhil Joshi <nitin.nitinperderusted.rastogi@gmail.com> writes: > guys help me in making thi program? We can better help if you can show us what your initial try looks like, and tell us what it's doing instead of printing a '*'.
[toc] | [prev] | [next] | [standalone]
| From | Nikhil Joshi <nitin.nitinperderusted.rastogi@gmail.com> |
|---|---|
| Date | 2012-10-23 09:03 -0700 |
| Message-ID | <b0814c0d-1dad-465e-bb14-73e5469254fc@googlegroups.com> |
| In reply to | #27582 |
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?
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2012-10-23 12:35 -0400 |
| Message-ID | <5086C740.2070909@verizon.net> |
| In reply to | #27585 |
On 10/23/2012 12:03 PM, 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++)
> {
You should #include <stdio.h> at the top of your program, before using
the following functions.
> printf("*");
> printf("\n");
> }
> }
> getch();
That is not a C standard library function. You should avoid using such
functions unless necessary. If it is necessary, your program will not be
portable to systems where getch() is not provided, or has different
behavior than you expect it to have, so you need to know which systems
your program is intended to run on, and you should also let us know.
> }
>
>
>
> this is basic structure printing star..but dont know how make a program for star?
You need to tell us more precisely what it is you want your program to
do. Except for the two issues I've raised, the behavior of your program
is quite clear, but it's not clear how it fails to meet your needs.
[toc] | [prev] | [next] | [standalone]
| From | Joe Pfeiffer <pfeiffer@cs.nmsu.edu> |
|---|---|
| Date | 2012-10-23 10:45 -0600 |
| Message-ID | <1b4nllyw5a.fsf@new-snowball.wb.pfeifferfamily.net> |
| In reply to | #27585 |
Newsgroups: comp.lang.c
Subject: Re: Write a program to print star using * ?
From: Joe Pfeiffer <pfeiffer@cs.nmsu.edu>
--text follows this line--
Nikhil Joshi <nitin.nitinperderusted.rastogi@gmail.com> writes:
> 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?
First, get in the habit of indenting your code for readability and
declaring functions correctly:
int main(void)
{
int i,j;
for(i=0;i<5;i++)
{
for(j=i;j<5;j++)
{
printf("*");
printf("\n");
}
}
getch();
}
OK, your program prints a column of 25 *'s. Please try to say more
completely what it's supposed to do instead (and what you've tried to
do to get it to do it).
[toc] | [prev] | [next] | [standalone]
| From | pete <pfiland@mindspring.com> |
|---|---|
| Date | 2012-10-23 15:45 -0400 |
| Message-ID | <5086F3C1.2FED@mindspring.com> |
| In reply to | #27585 |
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 */
#include <stdio.h>
int
main(void)
{
puts(" * ");
puts(" ");
puts(" ");
puts(" ");
puts("* * * *");
puts(" ");
puts(" ");
puts(" ");
puts(" * * ");
puts(" ");
puts(" ");
puts(" * ");
puts(" ");
puts(" ");
puts(" * * ");
return 0;
}
/* END new.c */
--
pete
[toc] | [prev] | [next] | [standalone]
| From | Joe Pfeiffer <pfeiffer@cs.nmsu.edu> |
|---|---|
| Date | 2012-10-23 19:45 -0600 |
| Message-ID | <1btxtky76l.fsf@new-snowball.wb.pfeifferfamily.net> |
| In reply to | #27599 |
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 */
>
> #include <stdio.h>
>
> int
> main(void)
> {
> puts(" * ");
> puts(" ");
> puts(" ");
> puts(" ");
> puts("* * * *");
> puts(" ");
> puts(" ");
> puts(" ");
> puts(" * * ");
> puts(" ");
> puts(" ");
> puts(" * ");
> puts(" ");
> puts(" ");
> puts(" * * ");
> return 0;
> }
>
> /* END new.c */
Hey -- don't just do his homework for him!
[toc] | [prev] | [next] | [standalone]
| From | pete <pfiland@mindspring.com> |
|---|---|
| Date | 2012-10-24 02:58 -0400 |
| Message-ID | <508791B0.4173@mindspring.com> |
| In reply to | #27614 |
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 */
**
****
*****
******
********
*** ***
**** ****
************
*************
** **
**** ****
***** *****
*************************************************
************************ ************************
**** **** ***** ***** ***** ***** **** ****
**** *** **** **** **** ***** *** ***
******** ************************ ********
****** ************************* *******
****** ** ***** ***** *** *****
**** **** **** **** *** ****
** ***** *** *** ***** ***
************** *************
************ *************
**** ***** ***** *****
**** **** ***** *****
************ ************
************* *************
** ****** ** *** ** ** **
**** **** **** *** ***** ****
***** *** ***** ***** *** *****
****** ************************** ******
******** ************************* ********
*** *** ****** ***** ***** ***** *** ***
**** **** **** ***** ***** ***** **** ****
****************** ***** ***** ******************
*************************************************
****** ******
**** *****
**** ***
**************
*************
********* **
**** ****
** ***
********
******
*****
****
**
/* END star.c output */
/* BEGIN star.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, j, x, y;
char array[D][D + 1];
char *const a = *array;
long unsigned seed = 123456789LU;
const struct {
size_t x;
size_t y;
} point[][3] = {
{
{ 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;
}
j = NMEMB(point);
while (j-- != 0) {
x = point[j][j].x;
y = point[j][j].y;
for (i = 0; i != sizeof array * sizeof array; ++i) {
seed = seed * 69069LU + 362437LU & 0XFFFFFFFFLU;
x = (x + point[j][seed % NMEMB(*point)].x) / 2;
y = (y + point[j][seed % NMEMB(*point)].y) / 2;
array[x][y] = '*';
}
}
puts("/* BEGIN star.c output */\n");
for (i = 0; i != sizeof array; ++i) {
putchar(a[i]);
}
puts("/* END star.c output */");
return 0;
}
/* END star.c */
--
pete
[toc] | [prev] | [next] | [standalone]
| From | pete <pfiland@mindspring.com> |
|---|---|
| Date | 2012-10-25 23:23 -0400 |
| Message-ID | <508A021C.387C@mindspring.com> |
| In reply to | #27618 |
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
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lpitcher@teksavvy.com> |
|---|---|
| Date | 2012-10-26 09:52 -0400 |
| Message-ID | <dAwis.2099$mC.2045@newsfe16.iad> |
| In reply to | #27708 |
On Thursday 25 October 2012 23:23, in comp.lang.c, pfiland@mindspring.com wrote: [snip] > And now, > because it's almost the same program, > something that resembles a Koch snowflake: > > /* BEGIN snowflake.c output */ [snip] Double Plus One good :-) -- Lew Pitcher "In Skills, We Trust"
[toc] | [prev] | [next] | [standalone]
| From | pete <pfiland@mindspring.com> |
|---|---|
| Date | 2012-10-26 20:35 -0400 |
| Message-ID | <508B2C40.3E76@mindspring.com> |
| In reply to | #27726 |
Lew Pitcher wrote:
>
> On Thursday 25 October 2012 23:23, in comp.lang.c, pfiland@mindspring.com
> wrote:
> [snip]
> > And now,
> > because it's almost the same program,
> > something that resembles a Koch snowflake:
> >
> > /* BEGIN snowflake.c output */
> [snip]
>
> Double Plus One good :-)
Thank you.
I was surprised to find out that the weak PRNG,
which I had used to make the star
out of two Sierpinski triangles in the previous program
(as per your recomendation to superimpose two triangles),
wasn't good enough for the snowflake.
When I used the exact same PRNG as before,
the snowflake looked the this:
/* BEGIN snowflake.c output */
***
***
**
**
*
*
* ***
* *
** ** ** * ***
*** ** * *** ****
* ** ** **
*** ** **
** ** *
*
** ***
** **
*** ** *
*** ** ***
* **
**
*
*
*
** ** ***
*** ** ****
* ** **
*** **
** *
*
** * ***
** * **
*** * ** *
*** *** ** * ** ***
* * * **
** **
*** *
**
**
**
**
* ***
**
/* END snowflake.c output */
--
pete
[toc] | [prev] | [next] | [standalone]
| From | "copiga@h_o_t_mail.co.uk" <copiga@h_o_t_mail.co.uk> |
|---|---|
| Date | 2012-10-23 11:21 -0500 |
| Message-ID | <mrqdnUg425xvXhvNnZ2dnUVZ8t-dnZ2d@bt.com> |
| In reply to | #27582 |
Nikhil Joshi wrote:
> guys help me in making thi program?
int main(void){
char star='*'
printf ("%c", star);
return 0;
}
like this?
[toc] | [prev] | [next] | [standalone]
| From | "BartC" <bc@freeuk.com> |
|---|---|
| Date | 2012-10-23 17:25 +0100 |
| Message-ID | <k66gfr$guv$1@dont-email.me> |
| In reply to | #27582 |
"Nikhil Joshi" <nitin.nitinperderusted.rastogi@gmail.com> wrote in message news:9291e324-bdc8-4153-b40e-4c53fc4bcec3@googlegroups.com... > guys help me in making thi program? What shape of star? And how big? Solid or outline? Text output or image? Colour, greyscale or mono? Give an example just using text (assume we have a fixed pitch display). Then it'll be easier to see how to achieve it programmatically. -- Bartc
[toc] | [prev] | [next] | [standalone]
| From | Kenneth Brody <kenbrody@spamcop.net> |
|---|---|
| Date | 2012-10-23 13:21 -0400 |
| Message-ID | <x46dnWa8VempTxvNnZ2dnUVZ_sKdnZ2d@bestweb.net> |
| In reply to | #27582 |
On 10/23/2012 11:52 AM, Nikhil Joshi wrote:
> guys help me in making thi program?
>
Assuming that "this program" is the one referenced in the subject -- "a
program to print star using *" -- what's wrong with:
========
#include <stdio.h>
int main(void)
{
puts("*"); // Print an asterisk (aka "star")
return(0);
}
========
If that's not what you meant, then tell us what it is you are trying to do,
show us what you've done so far, and describe the problem that your code
exhibits.
--
Kenneth Brody
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lpitcher@teksavvy.com> |
|---|---|
| Date | 2012-10-23 21:59 -0400 |
| Message-ID | <nYHhs.15$iq6.13@newsfe21.iad> |
| In reply to | #27582 |
On Tuesday 23 October 2012 11:52, in comp.lang.c,
nitin.nitinperderusted.rastogi@gmail.com wrote:
> guys help me in making thi program?
Sure
This is a star
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
*
***
*****
***************
*************
***********
*************
***************
*****
***
*
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It is made up of two triangles
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
*
***
*****
*******
*********
***********
*************
***************
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
and
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
***************
*************
***********
*********
*******
*****
***
*
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
superimposed over each other.
The contents of each row of each triangle has a mathemetical relationship to
the order of the row; both the number of stars, and the number of spaces to
indent to the first star can be computed knowing only the row number.
Now, all you have to do is formulate a loop that builds the star in rows;
computing the number of stars and the indent for each row of each triangle,
and superimposing one triangle over the other.
It's just a simple matter of programming.
--
Lew Pitcher
"In Skills, We Trust"
[toc] | [prev] | [next] | [standalone]
| From | Nick Keighley <nick_keighley_nospam@hotmail.com> |
|---|---|
| Date | 2012-10-27 06:05 -0700 |
| Message-ID | <5c63195e-c426-4cf0-bd16-c74c54e84066@s14g2000vba.googlegroups.com> |
| In reply to | #27582 |
On Oct 23, 4:52 pm, Nikhil Joshi
<nitin.nitinperderusted.rast...@gmail.com> wrote:
subject: write a program to print a star
> guys help me in making thi program?
#include <stdio.h>
#include "universe.h"
// not standard
#pragma use_star_printer
int main (void)
{
printf ("%S", STAR_POLARIS);
return 0;
}
do not run this program near (<100AU) other stellar bodies as it may
cause Undefined Behaviour
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c
csiph-web