Write a program to print star using * ?

Discussion in 'C Programming' started by Nikhil Joshi, Oct 23, 2012.

  1. Nikhil Joshi

    Nikhil Joshi Guest

    guys help me in making thi program?
     
    Nikhil Joshi, Oct 23, 2012
    #1
    1. Advertising

  2. Nikhil Joshi

    Joe Pfeiffer Guest

    Nikhil Joshi <> 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 '*'.
     
    Joe Pfeiffer, Oct 23, 2012
    #2
    1. Advertising

  3. Nikhil Joshi

    Nikhil Joshi Guest

    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?
     
    Nikhil Joshi, Oct 23, 2012
    #3
  4. Nikhil Joshi

    BartC Guest

    "Nikhil Joshi" <> wrote in message
    news:...
    > 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
     
    BartC, Oct 23, 2012
    #4
  5. Nikhil Joshi

    James Kuyper Guest

    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.
     
    James Kuyper, Oct 23, 2012
    #5
  6. Nikhil Joshi

    Joe Pfeiffer Guest

    Newsgroups: comp.lang.c
    Subject: Re: Write a program to print star using * ?
    From: Joe Pfeiffer <>
    --text follows this line--
    Nikhil Joshi <> 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).
     
    Joe Pfeiffer, Oct 23, 2012
    #6
  7. Nikhil Joshi

    Joe Pfeiffer Guest

    pete <> 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!
     
    Joe Pfeiffer, Oct 24, 2012
    #7
  8. Nikhil Joshi

    Lew Pitcher Guest

    On Tuesday 23 October 2012 11:52, in comp.lang.c,
    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"
     
    Lew Pitcher, Oct 24, 2012
    #8
  9. Nikhil Joshi

    Lew Pitcher Guest

    On Thursday 25 October 2012 23:23, in comp.lang.c,
    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"
     
    Lew Pitcher, Oct 26, 2012
    #9
  10. On Oct 23, 4:52 pm, Nikhil Joshi
    <> 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
     
    Nick Keighley, Oct 27, 2012
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Davis

    Service call failed: Star Wars

    Jon Davis, Feb 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    314
    Jon Davis
    Feb 3, 2004
  2. Stan Accrington
    Replies:
    1
    Views:
    970
    Michael Borgwardt
    May 13, 2004
  3. Replies:
    3
    Views:
    3,241
  4. keto
    Replies:
    0
    Views:
    1,024
  5. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    390
    David Cournapeau
    Dec 30, 2008
Loading...

Share This Page