1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Pls someone help me...

Discussion in 'C' started by bsit01, Sep 9, 2009.

  1. bsit01

    bsit01 New Member

    Joined:
    Sep 9, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    how to make a program that will make an output of a triangle figure composed of astirisks using C++.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    So, you've just started on a programming course, eh? How did I guess.

    Break it down into simple steps. Start with a program that prints a line of stars.

    Then change it so that it prints a line of n stars where you can specify the value of n (within the program).
    Code:
    int n=5;
    // code that prints a line of n stars
    
    Then can you think of a way to repeat that line over and over with n increasing from 1 to a maximum value? Hint: you'll probably have used the same statement in printing a line of n stars.
     
  3. bsit01

    bsit01 New Member

    Joined:
    Sep 9, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    can u teach me how to make a figure of triangle composed of astirisks by using loopings?
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    If what I just posted doesn't answer that question, then no, obviously I can't.
     
  5. bsit01

    bsit01 New Member

    Joined:
    Sep 9, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include<stdio.h>
    main()
    {
    int x,y,z;
    for(x=1;x<=40;x+=2)
    {
    for(y=1;y<=40-x;y+=2)
    {
    printf(" ");
    }
    for(z=1;z<=x;z++)
    {
    printf("*");
    }
    printf("\n");
    }
    }
     
    Last edited by a moderator: Sep 17, 2009
  6. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    Good work :)
    But, please always post code within [noparse]
    Code:
    .....
    [/noparse]

    And, as you have not mentioned the return type of main(), it's int by default; so remember to add return 0; at the end.
     
  7. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    the coding is written for a simple floyd triangle looking like below!
    *
    * *
    * * *
    * * * *
    * * * * *
    * * * * * *
    * * * * * * *
    here th no. of lines is :7
    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int m;
    clrscr();
    printf("enter the terms :");
    scanf("%d",&m);
    for(int i=1;i<=n;i++)
     {
         for(int j=1;j<=n-i;j++)
          printf(" ");
            for(j=1;j<=i;j++)
              printf("* ");
          printf("\n");
    }
    getch();
    }
    
    
    thank u:worried::)
     
  8. bsit01

    bsit01 New Member

    Joined:
    Sep 9, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    how to make multiplication table using c++?
     
  9. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    What do you want the program to display?
    Can you work out how to display part of that display?
    For example a multiplication table might read
    1x2=2
    2x2=4
    3x2=6
    Let's leave the difficult part of working out the solution for now, so let's write a program that just displays
    1x2=
    2x2=
    and so on.
    Can you work out how to do that?
     

Share This Page