Jump to content

how to write tis program code

- - - - -

  • Please log in to reply
12 replies to this topic

#1
2612

2612

    Newbie

  • Members
  • Pip
  • 1 posts
*
**
***
****
*****

#2
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
What code do you have so far? Where are you stuck? You can solve this with 2 loops; one that will count rows and one that will count how many stars to print.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#3
espdev-darkness

espdev-darkness

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
Is this what you meant?

//Staircase Output

#include <iostream>

#include <string>


using namespace std;


int main()

{

	string stair = "*";


	for (int i = 0; i < 80; ++i)

	{

		cout << stair << endl;

		stair += "*";

	}


	cin.get();

	return 0;

}


That will make a staircase out of *'s. The command line interface is only 80 characters wide so the largest staircase can go until 80.

Edit: You could use a c-type string since you know the maximum size of the string (80 + 1). Although I like using the string library.

#4
lina

lina

    Learning Programmer

  • Members
  • PipPipPip
  • 34 posts
do you still need help with this program? we did one similar in class, I may help!

#5
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
He probably moved on to something else, thanks lina.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#6
Hamed

Hamed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
#include <iostream>

using namespace std;

int main()
{
    int x;
    cin>>x;
    for(int i =1;i<=x;i++)
    {
        for(int j =i;j>0;j--)
        {
            cout<<"*";
        }
        cout<<endl;
    }
    return 0;
}
Another way!

#7
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
I am wondering how many people join forums just to get a problem solved then never come back. :c-biggrin:
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:

#8
espdev-darkness

espdev-darkness

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
@Hamed Nice code, I know everyone has their own style but your code seems really cramped... And your spacing is not the same all the way through. I would really suggest you fix things like
"for(int j =i;j>0;j--)" to make your syntax more readable by humans.

@Fread Yes it seems alot of people do, the sad part is when we tell them to try themselves they most likely migrate to another forum untill someone writes the code for them. I bet you he only logged on twice. Such a waste of space in the SQL database...

#9
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
You can use Functions. :)

# include <stdio.h>

# include <stdlib.h>

# include <conio.h>



void write(int x);

int main()

{

    int i, number;

    printf("Enter number of rows:");

    scanf("%d", &number);

    for (i=1; i<=number; i++)

    write(i);	

    getch();  

}


void write(int x){

int i;

for(i=0; i<x; i++)

printf("*");

printf("\n");

}




#10
espdev-darkness

espdev-darkness

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
The funny part is when this post was first made I was showing some friends the basics of C++ and I made a program similiar to yours with functions.

#11
lina

lina

    Learning Programmer

  • Members
  • PipPipPip
  • 34 posts
mmmmm

#12
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
2612
Program may be writed in many way. If you are biginer, the simplyest and easyest way is this:

# include <stdio.h>

# include <stdlib.h>

# include <conio.h>


int main()

{

puts("*");

puts("**");

puts("***");

puts("*****");

puts("******");

puts("*******");


getch();  

}


you can use printf but here you should add \n in printf. for example printf("** \n); \n means that you are on a next line. :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users