*
**
***
****
*****
12 replies to this topic
#1
Posted 29 November 2010 - 11:24 PM
|
|
|
#2
Posted 30 November 2010 - 04:14 AM
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
Posted 30 November 2010 - 06:35 AM
Is this what you meant?
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.
//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
Posted 12 December 2010 - 08:18 PM
do you still need help with this program? we did one similar in class, I may help!
#6
Posted 16 December 2010 - 02:30 AM
#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
Posted 16 December 2010 - 05:11 AM
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
Posted 16 December 2010 - 06:40 AM
@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...
"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
Posted 16 December 2010 - 09:43 AM
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
Posted 16 December 2010 - 02:44 PM
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
Posted 17 December 2010 - 04:18 PM
mmmmm
#12
Posted 18 December 2010 - 06:13 AM
2612
Program may be writed in many way. If you are biginer, the simplyest and easyest way is this:
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. :)
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


Sign In
Create Account

Back to top









