Write a program to print star using * ?

J

Joe Pfeiffer

Nikhil Joshi said:
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 '*'.
 
N

Nikhil Joshi

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?
 
B

BartC

Nikhil Joshi said:
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.
 
J

James Kuyper

main()
{
int i,j;
for(i=0;i<5;i++)
{
for(j=i;j<5;j++)
{

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.
 
J

Joe Pfeiffer

Newsgroups: comp.lang.c
Subject: Re: Write a program to print star using * ?
From: Joe Pfeiffer <[email protected]>
--text follows this line--
Nikhil Joshi said:
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).
 
J

Joe Pfeiffer

pete said:
/* 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!
 
L

Lew Pitcher

On Tuesday 23 October 2012 11:52, in comp.lang.c,
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.
 
L

Lew Pitcher

[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 :)
 
N

Nick Keighley

On Oct 23, 4:52 pm, Nikhil Joshi

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top