how to display this output ?

**********
*********
********
*******
******
*****
****
***
**
*
**
***
****
*****
******
*******
********
*********
**********


thank you...

Recommended Answers

All 3 Replies

Please show effort in trying to make the shape, and I will help you.

Here is a hint :

********** 10 stars
*********  9 stars
********   8 stars 
*******   7 stars
******  6 stars
***** 5 stars
**** 4 stars
***  3 stars
** 2 stars
* 1 stars
**  2 stars
*** 3 stars
**** 
*****
******
*******
********
*********
********** 10 stars

So you see that they decrease by 1 star until they reach 1 then they
start increment.

so assuming you can separate this problem into 2 blocks, you can
do something like this :

for(int i = 10; i != 1; i--)
     printStars(i); //a function that prints i stars with endl
for(int i = 2; i <= 10; i++)
     printStars(i);

Now what should your printStars look like :
for example if one calls printStars(4) it should output the following :

****

Go ahead and try to devise printStars then you problem becomes much
easier.

This should do...

#include<iostream>
using namespace std;
void printstar(int num_of_times);
void reverseprint(int highest);
int main()
{
 for(int i=0;i<10;i++){
 printstar(i);
 }
 reverseprint(10);
 return 0;
}

 void printstar(int num_of_times){
 for(int i=0;i<num_of_times;i++){
 cout<<"* ";
 }
 cout<<endl;
 }
 
 void reverseprint(int highest){
 for(int i=0;i<highest;i++){
 int x=highest-i;
 printstar(x);
 }
 cout<<endl;
 }

Please, if this satisfies your problem,mark this thread as solved.Thanks

"Show me your code and i will tell you who you are.."---Tkud

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.