Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>

void main()
{
    clrscr();

    int i,j,s=5,p,k=2,t;

    for(i=0;i<=4;i++)
    {
        cout<<setw(s);
        for(j=0;j<=i;j++)
        {
            cout<<"*";
            p=i;
        }
        if(j>1)
        {
            for(j=0;j<p;j++)
                cout<<"*";
            cout<<endl;
        }
        else
            cout<<endl;
        s--;
    }

    for(i=3;i>=0;i--)
    {
        cout<<setw(k);
        for(j=i;j>=0;j--)
            cout<<"*";

        for(j=i-1;j>=0;j--)
            cout<<"*";

        cout<<endl;
        k++;
    }

    getch();
}
Posted
Updated 25-Aug-13 5:51am
v2
Comments
Richard MacCutchan 25-Aug-13 4:25am    
This is a very simple homework problem, and the way to figure it out is to draw it on paper first, and see what your loop counts should be for every line.
kashiiii 25-Aug-13 4:30am    
i did,but can you please help me,by writing it in easy way

1 solution

"i did,but can you please help me,by writing it in easy way"

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

Oh - and learn to indent your code: it makes it a lot easier to read and to work out what is going on. It's also a very good idea to use meaningful names for your variables rather than "i", "j", "s" and so forth - again, it makes it much easier to work out what each variable does!
 
Share this answer
 
Comments
kashiiii 25-Aug-13 6:12am    
I am not doing my homework , just trying to improve my skills, thanks for your advise anyway :)
kashiiii 25-Aug-13 6:18am    
i Solved it myself
OriginalGriff 25-Aug-13 7:37am    
Well done!
(But, please - do try indenting and using "sensible names", it can make a huge difference to the readability of your code.)
Usman Hunjra 27-Aug-13 5:29am    
hello .. Kashiiii .. kis uni se hO. ?! :/
kashiiii 27-Aug-13 11:46am    
yes brother,punjab uni

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900