Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
My paper of Introduction To Programming is going to be help on 19/feb/2013...
I've to complete some programs before paper.
 
i want to print stars in this manner:
* * * * *
. * * * *
. . * * *
. . . * *
. . . . *
 
what if i declare a character to handle space like this char space = ' . ';
can i increment this space character .. ?!?!?!
 
For instance i write this:
int main()
{
	int length;
	cout << "Length: ";
	cin >> length;
	for (int i = 0; i < length; i++)
	{
		cout << "* ";
	}
	cout << endl;
	
}

 
I WILL UPDATE THE CODE AS SOON AS I GOT SOMETHING IN MY MIND..
Posted 16-Feb-13 23:46pm
ctype.h1.7K

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this:
for (int a = 5; a > 0; a--)
        {
            for (int b = 5; b >= a; b--)
            {
                cout<<".";
            }
            for (int c = a; c > 0; c--)
            {
                cout"*";
            }
            cout<<"\n";
 
        }
 
Hope it works fine
 
If you want make it till user defined value, write variable containing the user's value in place of 5
  Permalink  
v3
Comments
Philippe Mori at 17-Feb-13 22:07pm
   
It is almost that but it will have 1 dot too much.
 
As a side note, it is somewhat easier to understand if the code is written using loops that increment by one. Thus the outer loop would be the number of dot in a line. First inner loop would write dots. Then second inner loop would write asterisk. In that case, only 2 variables would be required for looping instead of 3.
 
This is left as an exercise to the reader.
Sarabjot Singh Makkar at 18-Feb-13 5:26am
   
initialize b with 4 and it will give the exact output
 
make b=4 in 3rd line.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 547
1 Member 11120668 188
2 ChauhanAjay 180
3 Maciej Los 165
4 CHill60 135
0 Sergey Alexandrovich Kryukov 9,735
1 OriginalGriff 6,987
2 CPallini 5,835
3 George Jonsson 4,017
4 Gihan Liyanage 3,266


Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100